Python元组列表:在 python中将元组附加到元组列表

我想在元组列表中添加一个元组:

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

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(271)
C is pr 32:Nodetool修复-pr-fullvsNodetool修复-pr
上一篇
Php获取当前日期时间:如何在PHP中获取当前日期和时间
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(21条)