cars = ['audi','bmw','subaru','toyota'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title())
输出结果:
Audi
BMW
Subaru
Toyota
True/False
if-elif-else结构
age = 12 if age <4: price = 0 elif age < 18: price = 10 elif age > 60: price = 15 else: price = 20 print(f"your cost is ${price}")