Skip to content

Commit 1db3f2f

Browse files
authored
Merge pull request #424 from lukaszwojcik89/patch-1
Update delattr.md
2 parents 124ced0 + 10c70c2 commit 1db3f2f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/builtin/delattr.md

+23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ Python delattr() built-in function
1616
</base-disclaimer-content>
1717
</base-disclaimer>
1818

19+
```python
20+
class Person:
21+
def __init__(self, name, age):
22+
self.name = name
23+
self.age = age
24+
25+
>>> person = Person("John", 30)
26+
>>> delattr(person, 'age')
27+
>>> person.__dict__
28+
# {'name': 'John'}
29+
30+
class Car:
31+
def __init__(self, make, model):
32+
self.make = make
33+
self.model = model
34+
35+
>>> car = Car("Toyota", "Corolla")
36+
>>> try:
37+
... delattr(car, 'year')
38+
... except AttributeError as e:
39+
... print(f"Error: {e}")
40+
# Error: 'Car' object has no attribute 'year'
41+
```
1942
<!-- remove this tag to start editing this page -->
2043
<empty-section />
2144
<!-- remove this tag to start editing this page -->

0 commit comments

Comments
 (0)