File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,31 @@ Python delattr() built-in function
1616 </base-disclaimer-content >
1717</base-disclaimer >
1818
19+ ## Examples
20+
21+ ``` python
22+ # Example 1
23+ class Person :
24+ def __init__ (self , name , age ):
25+ self .name = name
26+ self .age = age
27+
28+ person = Person(" John" , 30 )
29+ delattr (person, ' age' )
30+ print (person.__dict__ ) # Output: {'name': 'John'}
31+
32+ # Example 2
33+ class Car :
34+ def __init__ (self , make , model ):
35+ self .make = make
36+ self .model = model
37+
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'
43+ ```
1944<!-- remove this tag to start editing this page -->
2045<empty-section />
2146<!-- remove this tag to start editing this page -->
You can’t perform that action at this time.
0 commit comments