日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Java | Python 流程控制对比

發(fā)布時(shí)間:2024/4/15 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java | Python 流程控制对比 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?JavaPython?
數(shù)據(jù)類型

byte、short、int、long、float、double、char、boolean

數(shù)組、類、接口

Number(數(shù)字):?int、float、bool、complex(復(fù)數(shù))

String(字符串)

List(列表)

Tuple(元組)

Set(集合)

Dictionary(字典): 相當(dāng)于map?

?
if-else 1 int num = 3; 2 if (num > 0 && num < 4) { 3 System.out.println("4舍"); 4 } else if (num > 5 && num < 10) { 5 System.out.println("5入"); 6 } else { 7 System.out.println("不舍不入"); 8 }

?

1 num = 3 2 if num > 0 and num < 4: 3 print("4舍") 4 elif num > 5 and num < 10: 5 print("5入") 6 else: 7 print("不舍不入")

?

Python條件后面用冒號(hào) ,縮進(jìn)劃分語句塊

Python不支持&&

Python用?elif?代替?else if

三元運(yùn)算

1 int a = 3, b; 2 b = (a > 1) ? 200 : 400; ?1 a = 3 2 b = 200 if a > 1 else 400 3 print(b)?Python通過if-else實(shí)現(xiàn)三元運(yùn)算
while 1 int y = 1; 2 while (y < 10) { 3 System.out.println("y=" + y); 4 y++; 5 } 1 y = 1 2 while y < 10: 3 print('y =', y) 4 y += 1

Python不支持 i++

Python +和 Java并不一樣

Python不支持 do-while

for 1 for (int x = 0; x < 5; x++) { 2 for (int y = x + 1; y < 5; y++) { 3 System.out.print(" "); 4 } 5 6 for (int y = 0; y <= x; y++) { 7 System.out.print("* "); 8 } 9 System.out.println(); 10 } 1 x, y, z = 0, 0, 4 2 for x in range(5): 3 for y in range(z): 4 print(' ', end = '') 5 z -= 1 6 for y in range(x + 1): 7 print('* ', end = '') 8 print('\n', end = '') Python中end = '' 不換行
switch 1 char ch = '1'; 2 switch (ch) { 3 default: 4 System.out.println("error"); 5 break; 6 case '1': 7 System.out.println("兩"); 8 break; 9 case '2': 10 System.out.println("顆"); 11 break; 12 case '3': 13 System.out.println("糖"); 14 break; 15 } 1 def switch(var): 2 return { 3 '1': '', 4 '2': '', 5 '3': '' 6 }.get(var,'error') 7 print(switch('2')) ?Python通過字典實(shí)現(xiàn)switch
????
????

轉(zhuǎn)載于:https://www.cnblogs.com/sunjunxi/p/8494145.html

總結(jié)

以上是生活随笔為你收集整理的Java | Python 流程控制对比的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。