hasattr(object, name) Returns Boolean ( True or False ) after checking attribute of the input object
object Object for which the attribute is to be checked .
name name of the the attribute .
Read more on Class Object and Attributes
Output of hasattr() is True or False.
class Animal():

     #class attributes

     #instance attributes
    def __init__(self1,name1,age):
        self1.name= name1

 #instantiate the Animal  class
print(hasattr(tiger,'age'))    # True 
print(hasattr(tiger,'height')) # False 
In above code we got True for the attribute age , but got False for attribute height as it is not declared.
All Built in Functions in Python setattr() delattr() getattr()

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    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-2023 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer