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
19
19
## Examples
20
20
21
21
``` python
22
- # Example 1
23
22
class Person :
24
23
def __init__ (self , name , age ):
25
24
self .name = name
26
25
self .age = age
27
26
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'}
31
31
32
- # Example 2
33
32
class Car :
34
33
def __init__ (self , make , model ):
35
34
self .make = make
36
35
self .model = model
37
36
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'
43
43
```
44
44
<!-- remove this tag to start editing this page -->
45
45
<empty-section />
You can’t perform that action at this time.
0 commit comments