Built-in Functions and Types

delattr()

Delete an attribute chosen by a string. Like del target.name, this uses attribute deletion hooks and descriptor rules. Deleting an instance attribute can reveal a same-named class attribute rather than removing the name everywhere. Missing attributes or forbidden deletions usually raise AttributeError. A name must be a string.

Formal Syntax & Structure

python syntaxpython
delattr(object, name, /)

Parameters & Attributes

NameTypeDescription
objectobjectDeletion target.
namestrAttribute name to delete.

Return Value

None

Performs permitted deletion; returns None.

Working Example

Example Snippetpython
class Settings:    theme = "default"
settings = Settings()settings.theme = "dark"print(settings.theme)delattr(settings, "theme")print(settings.theme)
Python Reference