Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd4356d

Browse files
Update delattr.md
Added 2 examples of using delatrr() function
1 parent240f463 commitcd4356d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎docs/builtin/delattr.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
classPerson:
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+
classCar:
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+
exceptAttributeErroras 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-->

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp