File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -19,27 +19,27 @@ Python delattr() built-in function
1919## Examples
2020
2121``` python
22- # Example 1
2322class Person :
2423 def __init__ (self , name , age ):
2524 self .name = name
2625 self .age = age
2726
28- person = Person(" John" , 30 )
29- delattr (person, ' age' )
30- print (person.__dict__ ) # Output: {'name': 'John'}
27+ >> > person = Person(" John" , 30 )
28+ >> > delattr (person, ' age' )
29+ >> > person.__dict__
30+ # {'name': 'John'}
3131
32- # Example 2
3332class Car :
3433 def __init__ (self , make , model ):
3534 self .make = make
3635 self .model = model
3736
38- car = Car(" Toyota" , " Corolla" )
39- try :
40- delattr (car, ' year' )
41- except AttributeError as e:
42- print (f " Error: { e} " ) # Output: Error: 'Car' object has no attribute 'year'
37+ >> > car = Car(" Toyota" , " Corolla" )
38+ >> > try :
39+ ... delattr (car, ' year' )
40+ ... except AttributeError as e:
41+ ... print (f " Error: { e} " )
42+ # Error: 'Car' object has no attribute 'year'
4343```
4444<!-- remove this tag to start editing this page -->
4545<empty-section />
You can’t perform that action at this time.
0 commit comments