gpt4 book ai didi

python - 无法附加到返回的列表?

转载 作者:行者123 更新时间:2023-11-28 19:36:04 27 4
gpt4 key购买 nike

def f():
lst = ['a', 'b', 'c']
return lst[1:]

为什么是f().append('a') is None == True尽管 f().__class__<type 'list'>f() == ['b', 'c']

最佳答案

因为 append() 返回 None 而不是列表对象。使用

l = f()
l.append('a')
...

关于python - 无法附加到返回的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5996439/

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