加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python开发_python中的Boolean运算和真假值

发布时间:2020-12-17 00:19:00 所属栏目:Python 来源:网络整理
导读:python中的真假值: Any object can be tested truth value, use an condition 1.None 2.False 3.zero of any numeric type, span style="color: #0000ff;"for example,0.0span style="color: #000000;",0j. 4.any empty sequence,span style="color: #80000

python中的真假值:

Any object can be tested truth value, use an condition 1.None

2.False

3.zero of any numeric type,<span style="color: #0000ff;">for example,0.0<span style="color: #000000;">,0j.

4.any empty sequence,<span style="color: #800000;">''<span style="color: #000000;">,(),[].

5.any empty mapping,<span style="color: #0000ff;">for<span style="color: #000000;"> example,{}.

6.instances of user-defined classes,<span style="color: #0000ff;">if the <span style="color: #0000ff;">class defines a <span style="color: #800080;">bool() <span style="color: #0000ff;">or <span style="color: #800080;">len() method,when that method returns the integer zero <span style="color: #0000ff;">or bool value False. [1<span style="color: #000000;">]

All other values are considered true — so objects of many types are always true.

Operations <span style="color: #0000ff;">and built-<span style="color: #0000ff;">in functions that have a Boolean result always <span style="color: #0000ff;">return 0 <span style="color: #0000ff;">or False <span style="color: #0000ff;">for false <span style="color: #0000ff;">and 1 <span style="color: #0000ff;">or True <span style="color: #0000ff;">for true,unless otherwise stated. (Important exception: the Boolean operations <span style="color: #0000ff;">or <span style="color: #0000ff;">and <span style="color: #0000ff;">and always <span style="color: #0000ff;">return one of their operands.)

总结:

( if x is false,then y,else x x,y = 2 (.format(x,y,x x1,y1 = 0,10 (.format(x1,y1,x1 x2,y2 = (.format(x2,y2,x2 ( * 50 ( if x is false,then x,else y (.format(x,x x1,10 (.format(x1,x1 x2,0 (.format(x2,x2 ( * 50 ( if x is false,then True,else False x = 2 (.format(x, x = (.format(x, x))

Python 3.3.2 (v3.3.2:d047928ae3f6,May 16 2013,00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================ >>> y -> x false,2 0 = 2 10 = 10 0 = x y -> x false,2 0 = 10 = 0 = x -> x false, 2 = 0 =>>>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读