File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,29 @@ Python delattr() built-in function
16
16
</base-disclaimer-content >
17
17
</base-disclaimer >
18
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
+ ```
19
42
<!-- remove this tag to start editing this page -->
20
43
<empty-section />
21
44
<!-- remove this tag to start editing this page -->
You can’t perform that action at this time.
0 commit comments