在Python3中,列表理解可能是一个答案。。。?
[print(i) for i in range(5)]
print(i)
>> 0
1
2
3
4
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-598b4fd0c0c5> in <module>()
1 [print(i) for i in range(5)]
----> 2 print(i)
NameError: name 'i' is not defined