[root@localhost data]#
三:pass语句:
作用:
通常用来填充语法空白
num = int(input("请输入一个数字1-4:"))
if 1 <= num <= 4:
pass
else:
print("输入有错")
###########
[root@localhost data]# ./test.py
请输入一个数字1-4:3
[root@localhost data]# ./test.py
请输入一个数字1-4:7
输入有错
[root@localhost data]#
---------------------------------------------------------------------------------------------
布尔运算:
运算符:
notand or
布尔非操作: not
语法: not x
作用:对x 进行布尔取非,如bool(x)为True则返回False,否则返回True
布尔与操作:and
语法:xand y
注:x,y 代表表达式。
作用: 优先返回假值得对象,当x的布尔值为Fals时,返回x,否则返回y.
示意:True and True # 返回True
True and False #返回False
False and True #返回False
Fales and False #返回False
x = int(input("请输入一个月份:"))
if 1 <= x and x <= 12:
print("合法的月份")
else:
print("月份不合法")
###
[root@localhost data]# ./test.py
请输入一个月份:1
合法的月份
[root@localhost data]# ./test.py
请输入一个月份:8
合法的月份
[root@localhost data]# ./test.py
请输入一个月份:13
月份不合法
布尔或运算符:or
语法:x or y
作用:优先返回真值对象,当x为True时,返回x,否则返回y
示意:
True or True # True
True or False #True
Flase or True # True
Flase or False # False
x = int(input("请输入一个月份:"))
if x < 1 or x > 12:
print("输入有误")