2018-07-27 Chapter 5 If

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

##############################

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,934评论 0 23
  • 曾经蹭破了点皮,都要慌慌张张地告诉你。现在一个人感冒发烧,半夜反反复复起来喝水,熬了一整夜,也没想到要告诉你了。 ...
    范范er阅读 213评论 0 0
  • 在微信群里,和家长们一起探讨育儿的各种问题和经验,快一年的时间啦! 从最初的紧张到现在的自如,自己的成长可圈可点。...
    晓宏Nina阅读 102评论 0 1
  • 1.新增数据 insert into 表名 [(字段列表)] values (值列表) --1.主键冲突 当主键存...
    金克拉拉拉拉阅读 328评论 0 0