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')

 

上一篇:CCNP(ISCW)实验:配置AAA支持Radius


下一篇:使用Maven搭建SpringMVC项目