+ 5
What is happening here?
class A(): def __init__(a, b, c): print(b) A(8,3) #output: 8 Why is the output 8? At first I thought because the argument “a” is a substitute for “self”. Seeing that self is not a keyword, it can be anything. But when I run it like this class A(): def __init__(a, b, c): print(b) A(8,3,4) The debug catches it and says TypeError: Def __init__ Takes 3 positional arguments but 4 were given. I am at a loss.
3 Respostas
+ 8
figured it out.
a (normally ‘self’) is given implicitely by Python, that is why 4 are given.
+ 2
In your first option 'a' is 'self', and you gave values '8' and '3' to arguments 'b' and 'c' respectively. That is why the output 'b' is '8'.
0
thanks, yeah that is what I understood about it in my answer :) and self is implicitely given along, that was what confused me.0