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 d9349bf

Browse files
authored
Create static3.py
1 parent 2a2cba8 commit d9349bf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎docs/OOPS/static3.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Shared variables
2+
3+
'''
4+
What we need is a way to make an attribute shared across objects.
5+
The data is shared by all objects, not owned by each object.
6+
Thus, by making a single change, it should reflect in all objects at one go.
7+
'''
8+
9+
#Static
10+
11+
'''
12+
We can create shared attributes by placing them directly inside the class and not inside the constructor.
13+
And since this attribute is not owned by any one object, we don’t need the self to create this attribute.
14+
Such variables which are created at a class level are called static variables.
15+
Here discount is a static value.
16+
'''
17+
18+
19+
class Mobile:
20+
discount = 50
21+
def __init__(self, price, brand):
22+
self.price = price
23+
self.brand = brand

0 commit comments

Comments
(0)

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