if语句
程序员文章站
2024-03-25 20:08:46
...
- 实例:
home = ['aa','bb','cc','dd']
for homes in home:
if homes == 'aa':
print(homes.title())
else:
print(homes.upper())
输出结果为 Aa BB CC DD
- 关键词 in:判断列表是否包含特定值
home = ['aa','bb','cc','dd']
'aa' in home
结果为 True
'ss' in home
结果为 False
- if-else
age = 17
if age>=18:
print('nice')
else:
print('nono')
- if-elif-else
age = 12
if age<4:
print('small')
elif age>18:
print('big')
else:
print('nice')
上一篇: if语句