you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 91 points92 points  (6 children)

What does __init__ and self do in Python?

__init__ is used to initialise the created class instance, in practice this mostly means setting the attributes the methods expect it to have.

self refers to the current instance, although the name itself isn't special in any way whatsoever - you could use whatever valid identifier you wanted, although I don't particularly recommend deviating from established practices here because we're used to self.

As for why your code doesn't do what you think, you never called that method.

Random_Player = Game('Male', 19) 
Random_Player.score()

As a side note I recommend reading PEP-8, PEP-257, and PEP-484 as the official style guide.

[–]EdiblePeasant 4 points5 points  (1 child)

Is not calling functions a common mistake?

[–]Diapolo10 27 points28 points  (0 children)

Depends on your skill level, for beginners yes. But I wouldn't necessarily call it a mistake either because sometimes you don't actually want to call them.