Python3 —— if/while/input
生活随笔
收集整理的這篇文章主要介紹了
Python3 —— if/while/input
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ? Python3 —— if/while/input
?
目錄
? ? ? ? ? Python3 —— if/while/input
1.條件測試
2.if語句
3.input()函數
4.while循環
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
如果判斷為真,執行if后面語句;否則執行else后面語句。
(3)、if-elif-else結構(elif可以有多個)
比如車站收費:小于5歲免費,5~16歲半價,16歲以上全價。
3.input()函數
函數input()讓程序暫停運行,等待用戶輸入一些文本。使用input()函數時,返回的是字符串類型,int()函數將字符串轉換成整型數值。Python2.7里面使用raw_input()提示輸入。
4.while循環
與for作用一樣,都是循環。while條件為真,執行while里面程序。
?
5.break與continue
break退出循環;continue退出本次循環,執行下次循環。
?
?
?
總結
以上是生活随笔為你收集整理的Python3 —— if/while/input的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文件分卷压缩
- 下一篇: 2021 年下半年软考-初级程序员考后感