Python入门之chap5-if语句

一个简单示例

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语句

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}")
上一篇:scrapy 爬虫系列一、


下一篇:手机SIM卡介绍 三类不同标准的SIM卡