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

Commitda17576

Browse files
Update classmethod.md
1 parentd135e1a commitda17576

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

‎docs/builtin/classmethod.md‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ Python classmethod() built-in function
1616
</base-disclaimer-content>
1717
</base-disclaimer>
1818

19-
<!-- remove this tag to start editing this page-->
20-
<empty-section />
21-
<!-- remove this tag to start editing this page-->
19+
##Examples
20+
21+
```python
22+
classCounter:
23+
def__init__(self):
24+
self.count=0
25+
26+
defincrement(self):
27+
self.count+=1
28+
returnself.count
29+
30+
@classmethod# passes the class as the first argument to the method instead of passing the instance
31+
defget_new_instance(cls):
32+
returncls()
33+
34+
if__name__=="__main__":
35+
counter= Counter()
36+
print(counter.increment())
37+
# 1
38+
39+
counter= counter.get_new_instance()
40+
print(counter.increment())
41+
# 1
42+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp