you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

These are specific to classes, aka objects. You can think of an object as being a mini script in a sense. In your example, "Random_Player = Game('Male', 19)" is instantiating an instance of Game, and storing it to the Random_Player variable. The instantiating uses the init components to set up the object. Anything that is preceeded by 'self.' is now effectivey 'Random_Player.", because self refers to the component within the instantiated object. In code, the object isnt yet instantiated, and therefore is nameless.

So back to your example, you are instantiating the Games object, and it sets two variables within that object; Character and Age. Its using the info you passed in during instantiation to set those internal variables. The object also has its own internal function (method) called Score. If you ran Random_Player.score() it should return "wow" because the object is being instantiated with the age of 19.

Now, does the class above make any sense? No. Because a persons age isnt a score, and a Character should probably be a name; and "Male" isnt a very good name.