If
cars = ['audi', 'bmw', 'subaru', 'toyota']
for car in cars:
if car == 'bmw' :
print(car.upper())
else:
print(car.title())
> < >= <= () and or
age1 = 21
age2 = 65
if age1 >= 18 and age1 < 30:
print("age1 is " + str(age1) + ", so young people!")
if (age2 < 12) or (age2 >= 60):
print("age2 is " + str(age2) + ", child or old")
In
if ('audi' in cars):
print("audi is in cars")
if ('ddd' in cars):
print("ddd is in cars")
Not in
if ('ddd' not in cars):
print("ddd is't in cars")
else & elif
age1 = 15
if age1 < 4:
print("111")
elif age1 < 10:
print("222")
elif age1 < 18:
print("222")
else:
print("...")
List is null
list = []
if list:
for car in list:
print(car.upper())
else:
print("list is null")
##############################
Audi
BMW
Subaru
Toyota
age1 is 21, so young people!
age2 is 65, child or old
audi is in cars
ddd is't in cars
222
list is null
##############################
网友评论