Nov-06-2020, 03:37 PM
I came across similar code as bellow. It declare a variable foo.y and foo.z. They can be called outside the function.
I don't see this being explained in any tutorial.
Is this a common practice?
Can anyone please explain or give any lead on manual or info about this, thank you.
I don't see this being explained in any tutorial.
Is this a common practice?
Can anyone please explain or give any lead on manual or info about this, thank you.
def foo(x): foo.y = 2 foo.z = foo.y ** x return x * foo.y print(f'foo(3) is {foo(3)}') print(f'foo.y is {foo.y}') print(f'foo.z is {foo.z}')
Output:foo(3) is 6
foo.y is 2
foo.z is 8