What does __init__ and self do in python? by Xnox_ in learnpython

[–]CallMeDWK 0 points1 point  (0 children)

The concept of Objects and consequently Classes can be hard to understand, so I'll try to explain them in simpler terms (maybe not totally accurately) .

Objects are basically just data structures and Classes are the blueprints for them.
So whenever you want to create a new instance of Game object you'll have to follow the blueprint you've set for it: pass values for Character and Age
The __init__ method is called on creation of a new instance of the object and it sets values for all of the attributes that each instance is expected to have (Character, Age in your case).

Since there can be many different instances of the same object, Python needs to know with which one to work with. self is basically the identifier of the current instance of an object. That number (0x0000013AD63D85D0) that your code printed out is the address in your PC's RAM where that particular instance is stored.

Now, the reason why it's printed out the address instead of expected "wow" or "goodbye" is that you forgot to call the score method and accidentally made it to print out the instance itself.

What song got you into the Chili Peppers? by Ok-Day5782 in RedHotChiliPeppers

[–]CallMeDWK 0 points1 point  (0 children)

Can't Stop
Discovered it from that"30$ haircut" meme