【发布时间】:2020-04-05 08:31:22
【问题描述】:
我不明白这怎么可能?这里我使用i 的值作为for 循环,在for 循环之外。
for i, kv in enumerate(bucket):
k, v = kv
if key == k:
key_exists = True
break
#here is the issue...
if key_exists:
bucket[i] = ((key, value))
print(i)
else:
bucket.append((key, value))
【问题讨论】:
-
VTR,因为 OP there 询问 为什么 Python 没有块作用域。而是可能是 Block scope in Python 和/或 Short description of the scoping rules? 的副本
标签: python python-3.x for-loop