I agree that there is no block block. But one place in Python 3 makes it SEEM, as if it had a block scope.
What happened, what gave this look? This worked properly in Python 2. But to stop the variable leak in Python 3, they did this trick, and this change makes it look like it has a block scope here.
Let me explain.
According to the idea of โโa scope, when we introduce variables with the same name inside the same scope, its value should be changed.
this is what happens in python 2
>>> x = 'OLD' >>> sample = [x for x in 'NEW'] >>> x 'W'
But in Python 3, even if a variable with the same name is entered, it does not override, list comprehension acts for some reason as a sandbox and looks like creating a new scope in it.
>>> x = 'OLD' >>> sample = [x for x in 'NEW'] >>> x 'OLD'
and this answer goes against the answererer @Thomas statement . The only means to create a scope is functions, classes, or modules, because it looks like another place to create a new scope.
Harish Kayarohanam Jun 15 '18 at 23:17 2018-06-15 23:17
source share