0

I'm looking for documentations regarding __init__'s second argument.

In the snippet below, I instantiated an object of class test with a dict object, and actual content of this dict object was passed onto the test object via the second argument of the __init__ method.

So I think I know how this works and this is a really neat feature, however I would like to learn more about this but haven't been able to find any page that documents how this works in detail.

Could you please link me to a documentation that covers this, or explain to me how it works? Much appreciated!

aDict = {
    'a': 1,
    'b': 2
}

class test:
    def __init__(self, data):
        self.data = data

new_aDict = test(aDict)
new_aDict.data
{'a': 1, 'b': 2}
Mishka
  • 31
  • 2
  • `self` is implicitly passed as the first argument of any non-static class method, see link above – Cory Kramer Aug 13 '20 at 12:26
  • All functions of a class typically have the `self` attribute, as the first parameter, which allows you to reference member variables and functions from your own class. When you call these functions such as ``__init__``(as you do implicitly with the instantiation of the object), you don't need to pass self, that happens automatically. Any other arguments you pass then get shifted, so your `aDict` goes into the first argument of the function after init. – incarnadine Aug 13 '20 at 12:28
  • Thanks for the answers but I'm asking about the second parameter, which in the above snippet is the `data` attribute (the name doesn't matter). I know how `self` works, thanks. – Mishka Aug 13 '20 at 12:39

0 Answers0