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

Commit0239aaa

Browse files
committed
Adds a minimally plagiarized static method
docsFromhttps://docs.python.org/3/library/functions.html#staticmethodREF:wilfredinni#224
1 parentd135e1a commit0239aaa

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

‎docs/builtin/staticmethod.md‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,39 @@ Python staticmethod() built-in function
1515
Transform a method into a static method.
1616
</base-disclaimer-content>
1717
</base-disclaimer>
18+
The@staticmethod is a function decorator that will transform a class method into a static method that functions in a similar behavior to a C++ or other oop language static methods.
1819

19-
<!-- remove this tag to start editing this page-->
20-
<empty-section />
21-
<!-- remove this tag to start editing this page-->
20+
You can turn a class method into a static method by applying the <code>@staticmethod</code> decorator to a function in a class. For example:
21+
22+
```python
23+
>>>classC:
24+
>>>@staticmethod
25+
>>>deffunction():....
26+
```
27+
28+
Static methods can be called on the class itself like
29+
30+
```python
31+
>>>classClass:
32+
>>>@staticmethod
33+
>>>deffunction():
34+
>>>print("X")
35+
>>>
36+
>>> Class.function()
37+
>>># X
38+
```
39+
40+
Or on an instance of the class like
41+
42+
```python
43+
>>>classClass:
44+
>>>@staticmethod
45+
>>>deffunction():
46+
>>>print("X")
47+
>>>
48+
>>> new_class= Class()
49+
>>> new_class.function()
50+
>>># X
51+
```
52+
53+
The <code>@staticmethod</code> is in the form of a decorator the basics being it is a function that will return another function. This will be documented at a later time.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp