Python: Why cannot access variable in class

Viewed 69

The simple example:

class A():
   a = 1
   b = [a + i for i in range(3)]

It will raise

NameError: name 'a' is not defined

However,

class A():
   a = 1
   b = a + 2

works.

What is the basic access rule in Python3?

0 Answers
Related