Python元组运算符:
len(元组名):
返回元组对象的长度
# len(元组名):
# 返回元组对象的长度
tuple_1 = (1,4,5,2,3,6)
print(len(tuple_1))
# 6
+ 连接:
# + 连接
tuple_1 = (1,4,5)
tupel_2 = (3,5,4)
print(tuple_1 + tupel_2)
# (1, 4, 5, 3, 5, 4)
* 重复:
# * 重复
tuple_1 = (1,4,5)
num = 3
print(num * tuple_1)
# (1, 4, 5, 1, 4, 5, 1, 4, 5)
成员运算符 in ,not in:
# 成员运算符 in,not in
tuple_1 = (1,4,5,2,3,6)
print(4 in tuple_1)
# True
print(8 in tuple_1)
# False
print(4 not in tuple_1)
# False
print(8 not in tuple_1)
# True
将元组作为可迭代对象:
# 将元组作为可迭代对象
tuple_1 = ('a','b','c')
for i in tuple_1:
print(i , end = " ")
# a b c
2020-02-09