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

Commit 94f6575

Browse files
authored
Create static9.py
1 parent 84729c2 commit 94f6575

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎docs/OOPS/static9.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
We can access static methods directly using the class name, even without creating objects.
3+
'''
4+
5+
class Mobile:
6+
__discount = 50
7+
def __init__(self, price, brand):
8+
self.price = price
9+
self.brand = brand
10+
11+
def purchase(self):
12+
total = self.price - self.price * Mobile.__discount / 100
13+
print ("Total is ",total)
14+
15+
@staticmethod
16+
def get_discount():
17+
return Mobile.__discount
18+
19+
@staticmethod
20+
def set_discount(discount):
21+
Mobile.__discount = discount
22+
23+
print (Mobile.get_discount())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /