whitek 发表于 2018-8-7 09:56:35

Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式

view plaincopyprint?
[*]  def if_check():
[*]  if1:
[*]  print("1")
[*]  if0:
[*]  print("0")
[*]  if -100:
[*]  print("-100")
[*]  if100:
[*]  print("100")
[*]  ifTrue:
[*]  print("true")
[*]  ifFalse:
[*]  print("false")
[*]  def main():
[*]  if_check()
[*]  main()
<PRE style=&quot;&quot;display: none'&quot; class='\&quot;python\&quot;' name='\&quot;code\&quot;'>def if_check():
if 1:
print(\&quot;1\&quot;)
if 0:
print(\&quot;0\&quot;)
if -100:
print(\&quot;-100\&quot;)
if 100:
print(\&quot;100\&quot;)
if True:
print(\&quot;true\&quot;)
if False:
print(\&quot;false\&quot;)
def main():
if_check()
main()  运行结果如下所示。
  可以看出只有布尔表达式是0和False这两条if语句没有被执行,而布尔表达式为1 -100 100 True的if语句其下的打印语句都执行了。
页: [1]
查看完整版本: Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式