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 8a17bb0

Browse files
Data hiding in Python
1 parent 1bfa571 commit 8a17bb0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

‎lectures-code/data-hiding-1.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of Python course available on CourseGalaxy.com
3+
4+
class Product:
5+
def __init__(self):
6+
self.data1 = 10
7+
self._data2 = 20
8+
9+
def methodA(self):
10+
pass
11+
12+
def _methodB(self):
13+
pass
14+
15+
p = Product()
16+
17+
print(p.data1)
18+
p.methodA()
19+
print(p._data2)
20+
p._methodB()

‎lectures-code/data-hiding-2.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of Python course available on CourseGalaxy.com
3+
4+
class Product:
5+
def __init__(self):
6+
self.data1 = 10
7+
self.__data2 = 20
8+
9+
def methodA(self):
10+
pass
11+
12+
def __methodB(self):
13+
pass
14+
15+
p = Product()
16+
#print(p.__data2)
17+
#p.__methodB()
18+
print(p._Product__data2)
19+
p._Product__methodB()

0 commit comments

Comments
(0)

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