0
Why 2 why not 1?
Class A: x=0 def func(obj): obj.x=2 return obj a=A() a.x=1 b=func(a) print (a.x)
1 ответ
0
what 'func(a)' does is take 'a' and assign its attribute x=2 in the instance 'a'. So when you print (a.x) the result is 2.
When you pass a object as a parameter in a function, you can modify their attributes