Search⌘ K
AI Features

Name Resolution Ignoring Class Scope

Explore how Python manages name resolution within class scopes, including how nested scopes ignore names bound at the class level. Learn the differences between Python 2 and 3 regarding generator expressions and list comprehensions scopes to better write correct Python code.

We'll cover the following...

Look at the following code examples related to class scope:

1.

Can you predict the output of the following code?

Python 3.5
x = 5
class SomeClass:
x = 17
y = (x for i in range(10))
print(list(SomeClass.y)[0])

2.

Let’s modify the code a bit and run it ...