Skip to content

Commit f1cce18

Browse files
committed
added
1 parent ee50afe commit f1cce18

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

Encapsulation.ipynb

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "1527de64",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"class A:\n",
11+
" _a=10 #private\n",
12+
" __b=20 #Protected\n",
13+
" def show(self):\n",
14+
" print(\"a= \", self._a)\n",
15+
" print(\"b= \", self.__b)"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 2,
21+
"id": "0152a7de",
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"obj=A()"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 6,
31+
"id": "3d64114a",
32+
"metadata": {},
33+
"outputs": [
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"a= 10\n",
39+
"b= 20\n"
40+
]
41+
}
42+
],
43+
"source": [
44+
"obj.show()"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 10,
50+
"id": "67aa7f84",
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"name": "stdout",
55+
"output_type": "stream",
56+
"text": [
57+
"Protected Object calling outside of class 10\n"
58+
]
59+
}
60+
],
61+
"source": [
62+
"print(f\"Protected Object calling outside of class {obj._a}\")"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 11,
68+
"id": "605135d5",
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"ename": "AttributeError",
73+
"evalue": "'A' object has no attribute '__b'",
74+
"output_type": "error",
75+
"traceback": [
76+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
77+
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
78+
"Input \u001b[1;32mIn [11]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m private Object calling outside of class \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mobj\u001b[38;5;241m.\u001b[39m__b\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
79+
"\u001b[1;31mAttributeError\u001b[0m: 'A' object has no attribute '__b'"
80+
]
81+
}
82+
],
83+
"source": [
84+
"print(f\" private Object calling outside of class {obj.__b}\")"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"id": "902819a6",
91+
"metadata": {},
92+
"outputs": [],
93+
"source": []
94+
}
95+
],
96+
"metadata": {
97+
"kernelspec": {
98+
"display_name": "Python 3 (ipykernel)",
99+
"language": "python",
100+
"name": "python3"
101+
},
102+
"language_info": {
103+
"codemirror_mode": {
104+
"name": "ipython",
105+
"version": 3
106+
},
107+
"file_extension": ".py",
108+
"mimetype": "text/x-python",
109+
"name": "python",
110+
"nbconvert_exporter": "python",
111+
"pygments_lexer": "ipython3",
112+
"version": "3.9.12"
113+
}
114+
},
115+
"nbformat": 4,
116+
"nbformat_minor": 5
117+
}

0 commit comments

Comments
 (0)