pythonif結構允許程序做出選擇,并根據不同的情況執行不同的操作基本用法
比較運算符
根據PEP8標準,比較運算符兩側應該各有一個空格,比如:5==3。PEP8標準==(相等):如果該運算符兩側的值完全相同則返回True!=(不等):與相等相反
print(5=='5')
print(True=='1')
print(True==1)
print('Eric'.lower()=='eric'.lower())
>(大于):左側大于右側則輸出True
<(小于):與大于相反
>=(大于等于):左側大于或者等于右側則輸出True
<=(小于等于):左側小于或者等于右側則輸出True
print(5>3)
print(2>True)
print(True>False)
if的用法
if進行判斷
desserts=['icecream','chocolate','applecrisp','cookies']
favorite_dessert='applecrisp'
hate_dessert='chocolate'
fordessertindesserts:
ifdessert==favorite_dessert:
print("%sismyfavoritedessert!"%dessert.title())
以上內容為大家介紹了pythonif判斷在哪寫,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。