一.元组的创建
元组(tuple): 不可变数据类型
元组内可以存储任意数据类型
t = (1,2.3,True,'westos')
t1 = ([1,2,3],4)
t2 = ('westos',)
二.元组的特性
users = ('root','westos','redhat')
passwds = ('123','456','789')
索引 切片
print(users[0])
print(users[-1])
print(users[1:])
print(users[:-1])
print(users[::-1])
重复
print(users * 3)
连接
print(passwds + ('012','230'))
成员操作符
print('redhat' in users)
print('redhat' not in users)
迭代 (遍历)
for user in users:
print(user)
for index,user in enumerate(users):
print('第%d个用户: %s' %(index+1,user))
for user,passwd in zip(users,passwds):
print(user,':',passwd)