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

Commita56b955

Browse files
author
Vimal
committed
* Updated 30-staticmethod-2.py
* Renamed abstract_base_class.py -> 34-abstractclasses-1.py
1 parente6567fc commita56b955

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

‎30-staticmethod-2.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
from __future__importprint_function
3+
4+
# 30-staticmethod-2.py
5+
6+
# Refer
7+
# https://arvimal.wordpress.com/2016/06/12/instance-class-static-methods-object-oriented-programming/
8+
9+
# Static methods are functions/methods which doesn’t need a binding to a class or an instance.
10+
# Static methods, as well as Class methods, don’t require an instance to be called.
11+
# Static methods doesn’t need self or cls as the first argument since it’s not bound to an instance or class.
12+
# Static methods are normal functions, but within a class.
13+
# Static methods are defined with the keyword @staticmethod above the function/method.
14+
# Static methods are usually used to work on Class Attributes.
15+
16+
17+
classMyClass(object):
18+
# A class attribute
19+
count=0
20+
21+
def__init__(self,name):
22+
print("An instance is created!")
23+
self.name=name
24+
MyClass.count+=1
25+
26+
# Our class method
27+
@staticmethod
28+
defstatus():
29+
print("The total number of instances are ",MyClass.count)
30+
31+
print(MyClass.count)
32+
33+
my_func_1=MyClass("MyClass 1")
34+
my_func_2=MyClass("MyClass 2")
35+
my_func_3=MyClass("MyClass 3")
36+
37+
MyClass.status()
38+
print(MyClass.count)

‎abstract_base_class.py‎renamed to ‎34-abstractclasses-1.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
# 34-abstractclasses-1.py
4+
35
# This code snippet talks about Abstract Base Classes (abc)
46

57
importabc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp