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
  • 5,412
  • 7
  • 38
  • 70

0 Answers0