gpt4 book ai didi

python - 为什么 Python 列表没有范围限制(而整数有)?

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:36 25 4
gpt4 key购买 nike

<分区>

我的意思是,对于一个整数:

>>> a = 2
>>> def b():
... a += 1
...
>>> b()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in b
UnboundLocalError: local variable 'a' referenced before assignment

对于列表(或者说对于列表元素):

>>> a = [0]
>>> def b():
... a[0] += 1
...
>>> b()
>>> a[0]
1

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