gpt4 book ai didi

python - 分配给 list.extend 到 python 2.7 中的变量

转载 作者:行者123 更新时间:2023-11-28 17:31:01 24 4
gpt4 key购买 nike

<分区>

我刚开始学习 python,正在尝试使用列表方法。我遇到了这个问题;将 list.extend 分配给一个变量并没有像我想象的那样工作,我也不确定为什么。

alph = ["a", "b", "c"]
num = [0, 1, 2,]

num_alph = alph.extend(num)
print num_alph

打印 num_alph 没有结果,但我期待它打印这个;["a", "b", "c", 0, 1, 2]

将代码重写为这样可以得到预期的结果:

alph = ["a", "b", "c"]
num = [0, 1, 2,]

alph.extend(num)
num_alph = alph
print num_alph

为什么我以前的代码打印的不是扩展列表而是 none?

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