object() Return a new featureless object. It has the methods that are common to all instances of Python classes
x=object()
print(type(x)) # <class 'object'>
class student_kit():
college_name='ABC College' #class attributes
#instance attributes
def __init__(self,name,section):
self.name= name
self.section=section
self.height=5 #instance attribute
Alex=student_kit('Alex','A') # object declaration
print(Alex.name,Alex.section,Alex.height)
Alex()
The last line will generate error like this.
TypeError: 'student_kit' object is not callable
class student_kit():
college_name='ABC College' #class attributes
#instance attributes
def __init__(self,name,section):
self.name= name
self.section=section
self.height=5 #instance attribute
def __call__(self):
print('Hi , you called me')
Alex=student_kit('Alex','A') # object declaration
print(Alex.name,Alex.section,Alex.height)
Alex()
Output
Alex A 5
Hi , you called me
Here we have added __call__(self) so we can use Alex(). Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.