python中如何向元组中添加元素
作者:互联网
1、
>>> a = ("aaa","bbb","ccc","ddd","eee") >>> type(a) <class 'tuple'> >>> a[:2] + ("xxx",) + a[2:] ('aaa', 'bbb', 'xxx', 'ccc', 'ddd', 'eee') >>> a[:3] + ("xxx","yyy") + a[3:] ('aaa', 'bbb', 'ccc', 'xxx', 'yyy', 'ddd', 'eee') >>> a * 2 ('aaa', 'bbb', 'ccc', 'ddd', 'eee', 'aaa', 'bbb', 'ccc', 'ddd', 'eee') >>> b = ("xxx","yyy") >>> type(b) <class 'tuple'> >>> a + b ('aaa', 'bbb', 'ccc', 'ddd', 'eee', 'xxx', 'yyy') >>> b + a ('xxx', 'yyy', 'aaa', 'bbb', 'ccc', 'ddd', 'eee')
标签:aaa,python,xxx,bbb,元组,添加,eee,ccc,ddd 来源: https://www.cnblogs.com/liujiaxin2018/p/14444913.html