2021-03-27

‘’’
bicycles=[‘trek’,‘cannondale’,‘redline’,‘specialized’]
print(bicycles[0])
print(bicycles[0].title())
print(bicycles[-1]) #输出-1位置的元素(位置可变)
message=“My first bicycle was a “+bicycles[0].upper()+”.”
print(message)
‘’’
motorcycles=[‘honha’,‘yamaha’,‘suzuki’]
print(motorcycles)
‘’’
motorcycles[0]=‘ducati’ #修改第一个元素的值(位置可变)
print(motorcycles)
‘’’
‘’’
motorcycles.append(‘ducati’) #动态创建列表,在末尾添加元素(位置不可变)
print(motorcycles)
‘’’
‘’’
motorcycles.insert(1,‘ducati’) #insert添加元素(位置可变)
print(motorcycles)
‘’’
‘’’
del motorcycles[0] #删除第一个元素(位置可变)
print(motorcycles)
‘’’

‘’’
popped_motorcycles=motorcycles.pop()#pop()函数弹出栈顶元素,既最后一个元素,该元素被存储到popped_motorcycles
print(motorcycles)
print(popped_motorcycles)
print("The last motorcycles I owned was a "+popped_motorcycles.upper())
‘’’

‘’’
secand_motorcycles=motorcycles.pop(1)#将第二个元素移到secand_motorcycles中
print(motorcycles)
print(secand_motorcycles)
print("The secand motorcycles I owned was a "+secand_motorcycles)
‘’’
‘’’
motorcycles.remove(‘honha’) #remove函数通过元素值删除元素
print(motorcycles)
‘’’
Two=‘honha’
motorcycles.remove(‘honha’) #或者使用motorcycles.remove(Two)
print(motorcycles)
print(Two) #使用Two='honha’可以使元素继续使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值