【发布时间】:2013-10-28 11:09:25
【问题描述】:
我是 python 新手,我不确定if 条件的规则:
条件一:
if 0:
Print "true"
output:
条件2:
if -1:
Print "true"
output: true
条件 3:
if 1:
Print "true"
output: true
我将解释我的代码,
条件1:它没有打印语句,因为它被视为假(布尔值)
条件 2: 打印语句,因为它被视为 true(boolean)
为什么它取真,它是负值(我假设它只取假)?
条件 3:打印语句,因为它被视为 true(boolean)。
【问题讨论】:
-
在 python 和大多数语言中,除了 false、null 和 0 之外的所有内容都被视为 true。
标签: python