Use Python Reserved Word Class for Making Objects

This post will demonstrate use of the Python reserved word class.

Take a look at the following class called “PartyAnimal”.

class party animal

Class is a reserved word that you will use for making python objects. Class remembers the template for an object.

The above picture demonstrates a template for making objects.

The variable “x” will be part of every instance of this class.

After the variable, you have a method with a name (“party”) and parameter (“self”). By convention, “self” is always the first parameter. More parameters can follow.

You can then call the object, put it in the variable “an”. At this point, “an” is an object. You can do things to it based on the definition of the class. Essentially “” is a short form of “”.

If you run the code, it will output the following:

code output

The variable “self” acts as alias to “an”. It is like “self.x” is saying “x within self”.

find capability

Now, every string has all of the below methods.

string methods



Leave a Reply

Your email address will not be published. Required fields are marked *