Python中的元组与列表十分相似,元组是一种有序且不可变的序列。
创建元组
当元组中只有一个元素时,需要在元素后面加上逗号。
示例:
tup=('w','a','s','d')
_tup=(2,)
print(tup,_tup)
对元组的操作
因为元组无法被改变,使用append,pop,insert是非法的。尽管如此,我们仍可以结合两个元组或删除一整个元组。
示例:
tup=('English','maths','science')
tup2=('physics','chemistry')
tup3=tup+tup2 #结合元组
print(tup3)
del tup3 #删除元组
其他操作
对元组的其他操作,包括‘+’,‘*’,索引,截取与列表完全一致。
复习列表的函数
IYSTLZSJxo4
Thank you for sharing this insightful post. You did a fantastic job explaining your points. Looking forward to reading your next posts.
I’m impressed by your innate ability to turn ordinary topics into riveting writing. Well done!
This website is packed with helpful information. I like the extent of your expertise.
Hmm is anyone else experiencing problems with the pictures
on this blog loading? I’m trying to figure out if
its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.
Your blog entries are like little doses of radiance that illuminate my day. Thank you for that!
Thank you for offering such comprehensive and useful information. Your website is truly remarkable.