4 ms·
In Python 2, "[x for x in range(10)]; print(x)" prints 9. x is available outside the list comprehension. In Python 3, it raises a NameError, because the x in "
by duckerude 8y ago
In Python 2, "[x for x in range(10)]; print(x)" prints 9. x is available outside the list comprehension.
In Python 3, it raises a NameError, because the x in "print(x)" is not defined. It's contained in the list comprehension.
But I don't know a good use of the Python 2 behavior.