On this page
builtins.hasattr
Prev: builtins.globals | Up: builtins | Next: builtins.hash
Rel: builtins.abs, builtins.aiter, builtins.all, builtins.anext
Ref: docs.python.org — builtins.hasattr
Tags: #public #python3 #stdlib #builtins
Import
import builtins
from builtins import hasattr
Signature & Overview
builtins.hasattr(obj, name, /)
Return whether the object has an attribute with the given name.
Usage
assert hasattr("abc", "startswith") is True
assert hasattr("abc", "nope") is False
Gotchas
- Calls
getattr()under the hood: Invokes@propertygetters and swallows anyAttributeErrorraised inside a property—useinspect.getattr_static()to avoid side effects.
REPL Inspect
from builtins import hasattr
help(hasattr)
Linked from
Related notes
- tuts/python3/stdlib_module/builtins/globals Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/hash Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/builtins/abs Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/aiter Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/all Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/anext Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/any shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ArithmeticError shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ascii shared tags: #builtins, #stdlib