object()

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'>

Object as function

We can't call object as a function() like this example.
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

Let us add __call__(self) to this.
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().

So calling object as function ( with parenthesis () ) mean execution ojbects __call_(self) method.
All Built in Functions in Python
max() Bitwise operators using format() int() float()


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer