亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

?? ??? ??
Python是什么? Python 3 教程 Python3 基礎(chǔ)語(yǔ)法 編碼 Python3 基本數(shù)據(jù)類型 Python解釋器 Python 注釋 Python 數(shù)字運(yùn)算 Python 字符串 Python 列表 Python 編程第一步 Python 條件控制 Python 循環(huán) Python 函數(shù) Python 數(shù)據(jù)結(jié)構(gòu) Python 模塊 Python 輸入和輸出 Python 錯(cuò)誤和異常 Python 類 Python 標(biāo)準(zhǔn)庫(kù)概覽 Python Hello World 實(shí)例 Python 數(shù)字求和 Python 平方根 Python 二次方程 Python 計(jì)算三角形的面積 Python 隨機(jī)數(shù)生成 Python 攝氏溫度轉(zhuǎn)華氏溫度 Python 交換變量 Python if 語(yǔ)句 Python 判斷字符串是否為數(shù)字 Python 判斷奇數(shù)偶數(shù) Python 判斷閏年 Python 獲取最大值函數(shù) Python 質(zhì)數(shù)判斷 Python 階乘實(shí)例 Python 九九乘法表 Python 斐波那契數(shù)列 Python 阿姆斯特朗數(shù) Python 十進(jìn)制轉(zhuǎn)二進(jìn)制、八進(jìn)制、十六進(jìn)制 Python ASCII碼與字符相互轉(zhuǎn)換 Python 最大公約數(shù)算法 Python 最小公倍數(shù)算法 Python 簡(jiǎn)單計(jì)算器實(shí)現(xiàn) Python 生成日歷 Python 使用遞歸斐波那契數(shù)列 Python 文件 IO Python 字符串判斷 Python 字符串大小寫(xiě)轉(zhuǎn)換 Python 計(jì)算每個(gè)月天數(shù) Python 獲取昨天日期 Python list 常用操作 Python3 實(shí)例
??

Python 條件控制



if 語(yǔ)句

Python中if語(yǔ)句的一般形式如下所示:

if condition_1:
    statement_block_1
elif condition_2:
    statement_block_2
else:
    statement_block_3

如果 "condition_1" 為 True 將執(zhí)行 "statement_block_1" 塊語(yǔ)句,如果 "condition_1" 為False,將判斷 "condition_2",如果"condition_2" 為 True 將執(zhí)行 "statement_block_2" 塊語(yǔ)句,如果 "condition_2" 為False,將執(zhí)行"statement_block_3"塊語(yǔ)句。

Python中用elif代替了else if,所以if語(yǔ)句的關(guān)鍵字為:if – elif – else。

注意:

  • 1、每個(gè)條件后面要使用冒號(hào)(:),表示接下來(lái)是滿足條件后要執(zhí)行的語(yǔ)句塊。
  • 2、使用縮進(jìn)來(lái)劃分語(yǔ)句塊,相同縮進(jìn)數(shù)的語(yǔ)句在一起組成一個(gè)語(yǔ)句塊。
  • 3、在Python中沒(méi)有switch – case語(yǔ)句。

實(shí)例

以下實(shí)例演示了狗的年齡計(jì)算判斷:

age = int(input("Age of the dog: "))
print()
if age < 0:
	print("This can hardly be true!")
elif age == 1:
	print("about 14 human years")
elif age == 2:
	print("about 22 human years")
elif age > 2:
	human = 22 + (age -2)*5
	print("Human years: ", human)

### 
input('press Return>')

將以上腳本保存在dog.py文件中,并執(zhí)行該腳本:

python dog.py
Age of the dog: 1

about 14 human years

以下為if中常用的操作運(yùn)算符:

操作符 描述
< 小于
<= 小于或等于
> 大于
>= 大于或等于
== 等于,比較對(duì)象是否相等
!= 不等于

實(shí)例

# 程序演示了 == 操作符
# 使用數(shù)字
print(5 == 6)
# 使用變量
x = 5
y = 8
print(x == y)

以上實(shí)例輸出結(jié)果:

False
False

high_low.py文件:

#!/usr/bin/python3 
# 該實(shí)例演示了數(shù)字猜謎游戲
number = 7
guess = -1
print("Guess the number!")
while guess != number:
    guess = int(input("Is it... "))
 
    if guess == number:
        print("Hooray! You guessed it right!")
    elif guess < number:
        print("It's bigger...")
    elif guess > number:
        print("It's not so big.")
?? ??: ?? ??: