美文网首页
2018-07-07-python-逻辑操作符-and &or-

2018-07-07-python-逻辑操作符-and &or-

作者: mychineseheart | 来源:发表于2018-07-07 20:30 被阅读0次

1. 代码明细.

#逻辑运算符 and

#"10"  or "0"  结果为10

# "" or "0"  结果为0

x = int(input("请输入数据:") or "0" )

if 0<=x<=100:

    print("输入的数据合法")

if x >=0 and x<=100:

    print("输入的数据合法")

2.具体操作.

tarena@tedu:~/桌面$ python3 and.py

请输入数据:

输入的数据合法

输入的数据合法

3.代码说明.

此次代码只有一个非常细小的进步,就是,如果输入空字符,不会在报错了,而代码中用到了or 操作符.

4.others

tarena zhuhairui 2018.7.7 20:27xinfangcun


相关文章

网友评论

      本文标题:2018-07-07-python-逻辑操作符-and &or-

      本文链接:https://www.haomeiwen.com/subject/npnguftx.html