We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 124ced0 + 10c70c2 commit 1db3f2fCopy full SHA for 1db3f2f
docs/builtin/delattr.md
@@ -16,6 +16,29 @@ Python delattr() built-in function
16
</base-disclaimer-content>
17
</base-disclaimer>
18
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
+```
42
<!-- remove this tag to start editing this page -->
43
<empty-section />
44
0 commit comments