Instance as return values

Instance as return values:
Functions can return instances.For example,find_center takes a Rectangle as an argument and returns a Point that contains the coordinates of the center of the Rectangle:

def find_center(rect):
p=Point()
p.x=rect.corner.x+rect.width/2.0
p.y=rect.corner.y+rect.height/2.0
return p

1.Example for Instance

class Employee: 
id = 1512000; 
name = "Jack" 
def display (self): 
print("ID: %d \nName: %s"%(self.id,self.name)) 
emp = Employee() 
emp.display() 
 
Output:
ID: 1512000
Name: Jack
Translate »