标签:class 常用 div 循环 [1] item span 元组 font
元组
t1 = () print(t1, type(t1)) 结果:() <class ‘tuple‘>
参数为for可以循环的对象(可迭代对象)
t2 = tuple("123") print(t2, type(t2)) #(‘1‘, ‘2‘, ‘3‘) <class ‘tuple‘> t3 = tuple([1, 2, 3]) print(t3, type(t3)) #(1, 2, 3) <class ‘tuple‘> t4 = tuple((7, 8, 9)) print(t4, type(t4)) #(7, 8, 9) <class ‘tuple‘>
思考:如何定义一个只有一个值的元组
# "Owen" print(("Owen", )) print(tuple([‘Owen‘]))
常用操作
元组有序存储
索引取值
t = (1, 2, 3, 2, 3, 2) print(t[1]) #2 print(t[-2]) #3
切片
t = (1, 2, 3, 2, 3, 2)
print(id(t)) #2129098784520 nt = t[:-1:] print(nt, id(nt)) #(1, 2, 3, 2, 3) 2129098421328
长度(item元素个数)
t = (1, 2, 3, 2, 3, 2)
print(len(t)) #6
标签:class 常用 div 循环 [1] item span 元组 font
原文地址:https://www.cnblogs.com/tuzaizi/p/10612412.html