image
image
image

Making A Class Compatible with Inbuilt Special Functions

image

Example

Start IDLE.

Navigate to the File menu and click New Window.

Type the following:

class Planar:

def __init__(self, x_axis= 0, y_axis = 0):

self.x_axis = x_axis

self.y_axis = y_axis 

def __str__(self):

return "({0},{1})".format(self.x_axis,self.y_axis)

Discussion

planar1=Planar(3,5)

print(planar1)  #The output will be (3,5)