作者pttnewborn (pttnewborn)
看板Python
标题[问题] 请问范例
时间Fri Sep 11 06:56:10 2020
大家好:
刚学Python,书上有个范例如下
-------------------------------------
condiiton = 10
while condiiton:
print(condiiton)
condiiton -= 1
-------------------------------------
这范例是可以跑出结果来的(10,9,8,7,6....)
我的问题是while 後面不是要有判断式吗?
比如while condiiton>0:
因为他没写判断式,结果跟condition>0效果一样,
还是他是预设>0??
谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.216.21.143 (中国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1599778572.A.5F6.html
1F:推 TitanEric: condition是0的时候相当於false 所以跳出回圈 09/11 11:25
2F:→ xga00mex: 要的不是判断式 是要一个布林值 09/11 23:25
3F:推 dati: while 和 if 都可以直接给值,非零即执行 09/12 12:00