编程语言
首页 > 编程语言> > python中修改元组

python中修改元组

作者:互联网

 

>>> test1 = ("aaa","bbb","ccc","ddd","eee","fff","ggg")
>>> type(test1)
<class 'tuple'>
>>> test2 = test1[:4]
>>> test2
('aaa', 'bbb', 'ccc', 'ddd')
>>> test3 = test1[4:]
>>> test3
('eee', 'fff', 'ggg')
>>> insert = "xxx",
>>> test4 = test2 + insert + test3
>>> test1
('aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg')
>>> test4
('aaa', 'bbb', 'ccc', 'ddd', 'xxx', 'eee', 'fff', 'ggg')
>>> test5 = test1[:3]
>>> test5
('aaa', 'bbb', 'ccc')
>>> test6 = test1[4:]
>>> test6
('eee', 'fff', 'ggg')
>>> displace = "yyy",
>>> test7 = test5 + displace + test6
>>> id(test1)
2326018208096
>>> id(test7)
2326018299264
>>> test1
('aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg')
>>> test7
('aaa', 'bbb', 'ccc', 'yyy', 'eee', 'fff', 'ggg')

 

标签:test1,aaa,python,bbb,元组,修改,ggg,eee,fff
来源: https://www.cnblogs.com/liujiaxin2018/p/14171075.html