Python3 —— if/while/input
? ? ? ? ? ? ? ? ? ? ? ? ? ? Python3 —— if/while/input
?
目錄
? ? ? ? ? Python3 —— if/while/input
1.條件測試
2.if語句
3.input()函數(shù)
4.while循環(huán)
5.break與continue
1.條件測試
==?? 等于
!=?? 不等于
<??? 小于
<=?? 小于等于
>??? 大于
>=?? 大于等于
and? 與
or?? 或
not in 不在
?
2.if語句
(1)、最簡單的if語句
if condition:
???????? do something
注:注意冒號不要漏
(2)、if-else語句
if condition:
???????? do something1
else:
???????? do something2
如果判斷為真,執(zhí)行if后面語句;否則執(zhí)行else后面語句。
(3)、if-elif-else結(jié)構(gòu)(elif可以有多個)
比如車站收費:小于5歲免費,5~16歲半價,16歲以上全價。
3.input()函數(shù)
函數(shù)input()讓程序暫停運行,等待用戶輸入一些文本。使用input()函數(shù)時,返回的是字符串類型,int()函數(shù)將字符串轉(zhuǎn)換成整型數(shù)值。Python2.7里面使用raw_input()提示輸入。
4.while循環(huán)
與for作用一樣,都是循環(huán)。while條件為真,執(zhí)行while里面程序。
?
5.break與continue
break退出循環(huán);continue退出本次循環(huán),執(zhí)行下次循環(huán)。
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Python3 —— if/while/input的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文件分卷压缩
- 下一篇: python标准库怎么用_Python常