'''元组 不能被修改的列表 []索引'''
'''
tuple = (1,2,3,4,5,6)
print(tuple[2])
3
tuple[2]=100#尝试修改
print(tuple)
#报错TypeError
'''
'''遍历元组'''
'''tuple = (1,2,3,4,5,6)
for i in tuple:
print(i)
1
2
3
4
5
6'''
'''修改元组变量'''
'''tuple=(1,2)
for i in tuple:
print(i)
1
2
tuple=(3,4)
for i in tuple:
print(i)
3
4'''
'''
############################################
if 语句 if True/False
'''
'''cars=['audi','bmw','amg','toyota']
for i in cars:
if i=='bmw':
print(i.upper())
else:
print(i)
audi
BMW
amg
toyota'''
'''car='bmw'
if car in cars:
print(car.upper())
BMW'''
''' = 与 == ,= 是赋值,== 是判断相等,区分大小写,结果是布尔值'''
'''car='Audi'
print(car=='audi')
False
print(car.lower()=='audi')
True'''
''' != 是判断不相等,区分大小写,结果是布尔值'''
'''car='Audi'
print(car!='audi')
True
print(car.lower()!='audi')
False'''
'''== != > < >= <= 常用来比较数字'''
'''age=17
if age < 18:
print('你还未成年')
你还未成年'''
'''and 和 or 检查多条件 '''
'''True and True = True
True and False = False
False and False = False
False or False = False
False or True = True
True or True = True'''
'''age = 20
if (age>=18) and (age<=22): #True and False = True
print('你还不能结婚,太小了')
if (age>=18) or (age<=22): #True and False = True
print('你可以谈恋爱了')'''
'''检查列表是否包含某值,返回布尔值'''
'''cars = ['audi','amg','bmw']
print('bmw' in cars)
True
print('toyota' in cars)
False'''
'''检查列表不存在某值'''
'''cars = ['audi','bmw']
amg = 'amg'
if amg not in cars:
print(amg.title()+' is not exist')
Amg is not exist'''
'''布尔表达式记录条件,跟踪程序状态'''
game = True
study = False
'''if-else语句,if条件未通过就执行else后面的语句'''
'''age = 17
if age>18:
print('成年了')
else:
print('未成年')
未成年'''
'''if-elif-else语句 一次只运行一个代码段,if未通过执行elif,elif未通过执行else,elif可以有多个,else可以没有'''
'''age = 17
if age<15:
print(15)
elif age>18:
print(18)
else:
print('17')
17'''
'''if-if-if语句 同时运行多个代码段'''
'''cars = ['amg','bmw','toyota']
if 'amg' in cars:
print('amg')
if 'audi' in cars:
print('audi')
if 'toyota' in cars:
print('toyota')
amg
toyota'''
'''if语句处理列表'''
'''room = ['gang','liang','dong']
for name in room:
if name=='liang':
print('get out')
else:
print('welcome')
welcome
get out
welcome'''
'''确定列表不空'''
'''cars = []
if cars:#不空
print('人满了')
else:
cars.append('liang')
print('welcome'+str(cars))
welcome['liang']'''
'''使用多个列表'''
'''cars = ['amg','bmw','toyota','gang']
room = ['gang','liang','dong']
for name in room:
if name in cars:
print(name + ' have a car')
else:
print(name+' dont people have car')
print('finish')
gang have a car
liang dont people have car
dong dont people have car
finish'''
python教程二(列表2)
最新推荐文章于 2024-04-29 17:55:25 发布