代码块:
#元组(tuple): 不可变数据类型
#元组内可以存储任意数据类型
t = (1,2.3,True,'westos')
print(t)
print(type(t))
t1 = ([1,2,3],4)
t1[0].append(4)
print(t1)
t2 = ('westos',)
print(type(t2))
代码块:
users = ('root','westos','redhat')
passwds = ('123','456','789')
#索引 切片
print(users[0])
print(users[-1])
print(users[1:])
print(users[:-1])
print(users[::-1])
代码块:
users = ('root','westos','redhat')
passwds = ('123','456','789')
# 重复
print(users * 3)
代码块:
users = ('root','westos','redhat')
passwds = ('123','456','789')
#连接
print(passwds + ('012','230'))
代码块:
users = ('root','westos','redhat')
passwds = ('123','456','789')
#成员操作符
print('redhat' in users)
print('redhat' not in users)
代码块:
users = ('root','westos','redhat')
passwds = ('123','456','789')
#迭代
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)