Skip to content

Commit

Permalink
Merge pull request #424 from lukaszwojcik89/patch-1
Browse files Browse the repository at this point in the history
Update delattr.md
  • Loading branch information
wilfredinni authored Aug 3, 2024
2 parents 124ced0 + 10c70c2 commit 1db3f2f
Showing 1 changed file with 23 additions and 0 deletions.
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 -->

0 comments on commit 1db3f2f

Please sign in to comment.