On this page
  1. hasattr
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

help(hasattr)

Linked from

Related notes