We know that with the notation:
class Foo(object): a = 1 def __init__(self): self.b = 2 def c(self): print('c')
we can create a static variable Foo.a , 'normal' variable b , which will be available after creating and instantiating Foo , and the method c
Today I was very surprised that I can use conditional operators in the class, but outside the scope of the function
class C(): if True: a = 1 b = 2
Languages ββsuch as C ++ / Java taught me that legal notation is similar to:
class Name(): variable = <expression>
Could you describe other rules that apply to this particular area? What should I call this area?
scope python class conditional-statements
noisy
source share