|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
今天我在小甲鱼的课程上跟着用while循环模拟for循环:
>>> x = [1,1,2,3,5]
>>> _ = iter(x)
>>> while True:
try:
i = _.__next__()
except StopIteration:
break
print(i,end=' ')
1 1 2 3 5
但第三段代码的第三行我少写了一对括号:
>>> while True:
try:
i = _.__next__
except StopIteration:
break
print(i,end=' ')
然后,我看到了神奇的一幕:
>>> while True:
try:
i = _.__next__
except StopIteration:
break
print(i,end=' ')
<method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__next__' of list_iterator object at 0x0120B2E0> <method-wrapper '__nex......
我呆了十几秒才反应过来用 Ctrl + C 强制暂停,以至于我的电脑出现了11483行代码!
不怕电脑去世的可以去试试
|
|