hasattr()

Built-in FunctionPython 2.0+Intermediate

Returns True if an object has the given named attribute

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Dog:
    name = "Rex"
    def bark(self): pass

print(hasattr(Dog, "name"))
print(hasattr(Dog, "bark"))
print(hasattr(Dog, "fly"))

hasattr() is a built-in function that returns true if an object has the given named attribute.

Try in Playground

Tags

builtinfunctioncore