Skip to content

Commit a65f97b

Browse files
Added Example of public access specifier in python.
1 parent 9b06dc2 commit a65f97b

3 files changed

Lines changed: 138 additions & 29 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Created by .ignore support plugin (hsz.mobi)

.idea/workspace.xml

Lines changed: 108 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

accessspecifier/Cup.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Cup:
2+
def __init__(self):
3+
self.color = None
4+
self.content = None
5+
6+
def fill(self, beverage):
7+
self.content = beverage
8+
9+
def empty(self):
10+
self.content = None
11+
12+
def get_color(self):
13+
return self.color
14+
15+
def get_content(self):
16+
return self.content
17+
18+
19+
# Example of Public access specifier in python
20+
# All member variables and methods are public by default in Python.
21+
redCup = Cup()
22+
redCup.color = "red"
23+
print redCup.get_color()
24+
redCup.content = "tea"
25+
print redCup.get_content()
26+
redCup.empty()
27+
print redCup.get_content()
28+
redCup.fill("coffee")
29+
print redCup.get_content()

0 commit comments

Comments
 (0)