我想在元组列表中添加一个元组:
list1 = [('a', 'b'), ('c', 'd')]
tuple1 = ('e', 'f') # this is the tuple I want to add to the list above (list1).
list2 = list1.append(tuple1)
print(list2)
结果应该是:
[('a','b'),('c','d'),('e','f')]
但相反,我发现:
None
0
你刚刚做到了!看看你的清单1
list1=[('a','b'),('c','d')]
list2 = list1.copy()
list2.append('e','f')
print(list2)
解释
list.append () 方法只返回 None
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(21条)