cars = ['audi', 'subaru', 'bmw','toyota']
for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())
Python在条件判断时大小写敏感
a = 'H'
a == h # False
不等 !=
逻辑与 and
逻辑或 or
判断一个值是否在list里 in
判断一个值是否在list里 not in
布尔值首字母大写 True False
if - elif -else
age = 4
if age < 4:
print("Your admission cost is $0.")
elif age < 18:
print("Your admission cost is $25.")
else:
print("Your admission cost is $40.")
在Python中,最后的else判断不是必须的
判断list是否为空
requested_toppings = []
if requested_toppings:
print('Y')
else:
print('N')
代码风格:
运算符两边要有空格
if a == 4: