元组和集合的增删改查操作

元组:tuple 元组的元素不能修改。无增加删除修改操作

tup1 = (1, 2, 3, 4, 5 )
tup2 = "a", "b", "c", "d"
tup3 = tup1 + tup2  # 连接元组1和2后产生新的元组
tup3*2  # 重复输出
list(tup3)  # 转换为列表
len(tup3)
max(tup1)
min(tup1)
for i in tup1:
    print(i)
for i in range(len(tup1)):
    print(tup1[i])
tuple([1,2,3,4])  # 转换为元组
del tup3  # 删除元组

集合:无序,元素不可以重复,可用来去重

a1={
     1,2,3,5,8,9}
a1.add(88)  # 添加
set([1,2,3,5,8,5,6,5,8,])  # 去重

你可能感兴趣的:(python基础,python)