gpt4 book ai didi

python - 如何在python列表中的列表中添加一个元素?

转载 作者:太空宇宙 更新时间:2023-11-04 10:05:19 26 4
gpt4 key购买 nike

假设我有 2 个列表:

list = [[1, 2, 3], [4, 5]]  
a = 6

无论如何我可以把 a 放到 list[1][2] 位置吗?

最佳答案

是的,你可以这样做:

lst[1].append(a)

lst
# [[1, 2, 3], [4, 5, 6]]

关于python - 如何在python列表中的列表中添加一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41305253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com