if语句
# if后注意有冒号
age = 22
if age > 18:
print("age is", age)
print("adult")
if-else语句
# if 和 else 后有冒号
age = 22
if age > 18:
print("age is", age)
print("adult")
else:
print("age is", age)
print("teenager")
if-elif-else语句
age = 3
if age >= 18:
print('adult')
elif age >= 6:
print('teenager')
else:
print('kid')
判空
# 只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False。
if x:
print('True')
input的返回值是str
s = input('birth: ')
# 返回值是str,需要使用int函数转为整型
birth = int(s)
if birth < 2000:
print('00前')
else:
print('00后')