python教程二(列表2)

'''元组 不能被修改的列表 []索引'''
'''
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'''
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值