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
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 -->
You can’t perform that action at this time.
0 commit comments