Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/builtin/delattr.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ Python delattr() built-in function
</base-disclaimer-content>
</base-disclaimer>

```python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age

>>> person = Person("John", 30)
>>> delattr(person, 'age')
>>> person.__dict__
# {'name': 'John'}

class Car:
def __init__(self, make, model):
self.make = make
self.model = model

>>> car = Car("Toyota", "Corolla")
>>> try:
... delattr(car, 'year')
... except AttributeError as e:
... print(f"Error: {e}")
# Error: 'Car' object has no attribute 'year'
```
<!-- remove this tag to start editing this page -->
<empty-section />
<!-- remove this tag to start editing this page -->