1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
{
"metadata": {
"name": "",
"signature": "sha256:661266ea5854f8cdb4c1381d519c16a00dd0491ecb04f34e084c46771d5dc464"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 11: Pckages: Putting Classes Together"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"example 11.1, page no. 198"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\"\"\"\n",
"Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program\n",
"\"\"\"\n",
"\n",
"from package1 import *\n",
"from package2 import *\n",
"\n",
"a = classA()\n",
"b = classB()\n",
"\n",
"a.display()\n",
"b.displayB()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Class A\n",
"Class B\n",
"m = 10.0\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"example 11.2, page no. 200"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\"\"\"\n",
"Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program\n",
"\"\"\"\n",
"\n",
"from package2 import *\n",
"\n",
"class classC(classB):\n",
" n = 20\n",
" def displayC(self):\n",
" print \"Class C\"\n",
" print \"m = \", self.m\n",
" print \"n = \", self.n\n",
"\n",
"c = classC()\n",
"c.displayB()\n",
"c.displayC()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Class B\n",
"m = 10.0\n",
"Class C\n",
"m = 10.0\n",
"n = 20\n"
]
}
],
"prompt_number": 15
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"example 11.3, page no. 204"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\"\"\"\n",
"there is no concept of static import. We will use normal import instead\n",
"\"\"\"\n",
"\n",
"import math\n",
"\n",
"class mathop:\n",
" def circle(self, r):\n",
" area = math.pi*r*r\n",
" print \"The Area of circle is: \", area\n",
"\n",
"obj = mathop()\n",
"obj.circle(2.3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The Area of circle is: 16.6190251375\n"
]
}
],
"prompt_number": 16
}
],
"metadata": {}
}
]
}
|