0

I have this sample python 3 code:

class C:
    a = lambda x: x+1
    b = lambda y: a(y)*2

The class definition happens without any error. But when I attempt to call a class property b (which in turn tries to access a fellow class property a) I get an error:

C.b(1)

NameError: name 'a' is not defined

How can I reference class variables when defining other class variables?

hazrmard
  • 3,397
  • 4
  • 22
  • 36

0 Answers0