Creating a class

Now, after understanding some basic concepts of OOPs, let's understand them with some programming.

Creating a class in Python is quite easy. Refer to the following syntax:

 class <class name >(<parent class name>):
<method definition-1>
<method definition-n>

Let's create a class1.py program. In this program, we are creating an empty class:

class Leapx_org():
pass

We have just created a Leapx_org class. This class is empty, the class body just contains the pass statement. Basically, the class is a blueprint to create instances. Let's create the instances:

L_obj1 = Leapx_org()
L_obj2 = Leapx_org()
print L_obj1
print L_obj2

Let's run the class1.py program:

Output of program class1.py

In the preceding screenshot, you can see both the instances of the Leapx_org class at different locations in memory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.172.130