python菜鳥教程 if else 判斷

2021-10-08 04:29:50 字數 844 閱讀 4948

上一講我們學習了if語句,這一樣我們將要學習if else語句。

if condition:

true_expressions

else:

false_expressions

if判斷條件為true,執行true_expressions語句; 如果為false,將執行else的內部的false_expressions

x = 1

y = 2

z = 3

if x > y:

print('x is greater than y')

else:

print('x is less or equal to y')

在這個例子中,因為x > y將會返回false, 那麼將執行else的分支內容。輸出x is less or equal to y

x = 4

y = 2

z = 3

if x > y:

print('x is greater than y')

else:

print('x is less or equal y')

在這裡,因為condition條件為true, 那麼將會輸出

Python 函式 菜鳥教程

python3函式 菜鳥程式設計 計算面積函式 學習他的呼叫函式方式!def area width,height return width height w 4 h 5 print width w,height h,area area w,h width 4 height 5 area 20 pyt...

python 菜鳥教程 Python 元組

python 元組 python的元組與列表類似,不同之處在於元組的元素不能修改。元組使用小括號,列表使用方括號。元組建立很簡單,只需要在括號中新增元素,並使用逗號隔開即可。如下例項 例項 python 2.0 tup1 physics chemistry 1997,2000 tup2 1,2,3,...

python菜鳥教程函式 Python

python modf 函式 描述modf 方法返回x的整數部分與小數部分,兩部分的數值符號與x相同,整數部分以浮點型表示。語法以下是 modf 方法的語法 import math math.modf x 注意 modf 是不能直接訪問的,需要匯入 math 模組,通過靜態物件呼叫該方法。引數x 數...