name=['libai','dufu','dufu']
if name[0]=='libai':
print('hello,'+name[0].title())
else:
print('false')
print('\n')
#if判断列表元素【hello,libai】,注意冒号,缩进
#in 的用法 可以用来查找是否包含
number='123'
if number in name:
print(number)
else:
print('northing')
#not in ,注意这里’wo‘作为字符直接运用
if 'wo' not in name:
print('is right')
print('\n')
#这里注意valu其实是个变量,再循环中反复被赋值
for value in range(1,100):
if value>=90 and value<=100:
print(value)
print('\n')
# if 跟 elif一样的等级。都要执行,除了else
beisha='green'
if beisha=='green':
print('get 10 point')
elif beisha=='yellow':
print('get 5 poinr')
elif beisha=='red':
print('get 2 point')
else:
print('get 0 point')
print('\n')
favorite_food=['apple','banana','peach']
if 'apple'in favorite_food:
print('please get a apple')
if 'banana'in favorite_food:
print('please get a banana')
if 'peach'in favorite_food:
print('please get a peach')
print('\n')
#Python规定列表中至少包含一个元素时返回ture,并在列表为空时返回false
wo=['c']
if wo:
print('a')
else:
print('b')
第5章:if语句
最新推荐文章于 2023-02-19 11:33:26 发布