On this page
hasattr
Prev: globals | Up: __builtins__ | Next: hash
Rel: callable, delattr, dir, getattr, hash
Ref: docs.python.org — hasattr
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import hasattr
Overview & Signature
hasattr(obj, name, /)
Return whether the object has an attribute with the given name.
Usage
assert hasattr([1, 2], "append") is True
assert hasattr([1, 2], "nope") is False
Gotchas
- Calls
getattr()internally: Triggers@propertygetters and hides anyAttributeErrorraised inside the property—useinspect.getattr_static()if you want side-effect-free checks.
REPL Inspect
help(hasattr)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/callable
- tuts/python3/__builtins__/delattr
- tuts/python3/__builtins__/dir
- tuts/python3/__builtins__/getattr
- tuts/python3/__builtins__/globals
- tuts/python3/__builtins__/hash
- tuts/python3/__builtins__/id
- tuts/python3/__builtins__/isinstance
- tuts/python3/__builtins__/issubclass
- tuts/python3/__builtins__/repr
- tuts/python3/__builtins__/setattr
- tuts/python3/__builtins__/vars
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/callable Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/delattr Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/dir Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/getattr Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/globals Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/hash Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/id links to this page; shared tags: #builtins
- tuts/python3/__builtins__/isinstance links to this page; shared tags: #builtins