5

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?

chenzhongpu
  • 6,193
  • 8
  • 41
  • 79

0 Answers0