You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Status/Day_12.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,8 @@ print (squaredNumbers)
32
32
***Define a class named American which has a static method called printNationality.***
33
33
34
34
---------------------
35
-
### Hints: Use @staticmethod decorator to define class static method.
35
+
### Hints: Use @staticmethod decorator to define class static method.There are also two more methods.To know more, go to this [link](https://realpython.com/blog/python/instance-class-and-static-methods-demystified/).
36
+
36
37
---------------------
37
38
**Main Author's Solution: Python 2**
38
39
```
@@ -48,6 +49,17 @@ American.printNationality()
48
49
--------------------------
49
50
**My Solution: Python 3**
50
51
```
52
+
class American():
53
+
@staticmethod
54
+
def printNationality():
55
+
print("I am American")
56
+
57
+
american = American()
58
+
american.printNationality() # this will not run if @staticmethod does not decorates the function.
59
+
# Because the class has no inctance.
60
+
61
+
American.printNationality() # this will run even though the @staticmethod
0 commit comments