2
2
"cells" : [
3
3
{
4
4
"cell_type" : " markdown" ,
5
- "metadata" : {},
6
5
"source" : [
7
6
" # OOPS:\n " ,
8
7
" \n " ,
9
8
" Object Oriented Programming or OOP is working with classes and objects. It involves interaction between objects having various attributes.\n " ,
10
9
" \n " ,
11
10
" Python is a object oriented programming language. This meand that all the types are representation or instance of a type class."
12
- ]
11
+ ],
12
+ "metadata" : {}
13
13
},
14
14
{
15
15
"cell_type" : " markdown" ,
16
- "metadata" : {},
17
16
"source" : [
18
17
" ## Components:\n " ,
19
18
" 1. Class\n " ,
20
19
" 2. Object\n "
21
- ]
20
+ ],
21
+ "metadata" : {}
22
22
},
23
23
{
24
24
"cell_type" : " markdown" ,
25
- "metadata" : {},
26
25
"source" : [
27
26
" ## Class:\n " ,
28
27
" \n " ,
33
32
" Name of a class should start with an uppercase letter.\n " ,
34
33
" \n " ,
35
34
" Syntax: `class Class_name`"
36
- ]
35
+ ],
36
+ "metadata" : {}
37
37
},
38
38
{
39
39
"cell_type" : " code" ,
40
40
"execution_count" : 1 ,
41
- "metadata" : {},
42
- "outputs" : [],
43
41
"source" : [
44
- " class Student: \n " ,
45
- " roll_no = int()\n " ,
42
+ " class Students: \r \n" ,
43
+ " roll_no = int()\r\ n " ,
46
44
" name = str()"
47
- ]
45
+ ],
46
+ "outputs" : [],
47
+ "metadata" : {}
48
48
},
49
49
{
50
50
"cell_type" : " markdown" ,
51
- "metadata" : {},
52
51
"source" : [
53
52
" ## Object:\n " ,
54
53
" \n " ,
55
54
" It is an instance of a class.\n " ,
56
55
" \n " ,
57
56
" Syntax: `obj_name = Class_name()`"
58
- ]
57
+ ],
58
+ "metadata" : {}
59
59
},
60
60
{
61
61
"cell_type" : " code" ,
62
62
"execution_count" : 2 ,
63
- "metadata" : {},
64
- "outputs" : [],
65
63
"source" : [
66
- " student1 = Student () # creating a new object\n " ,
67
- " \n " ,
68
- " student1.roll_no = 1\n " ,
64
+ " student1 = Students () # creating a new object\r \n" ,
65
+ " \r\ n " ,
66
+ " student1.roll_no = 1\r\ n " ,
69
67
" student1.name = 'Prabhu'"
70
- ]
68
+ ],
69
+ "outputs" : [],
70
+ "metadata" : {}
71
71
},
72
72
{
73
73
"cell_type" : " code" ,
74
74
"execution_count" : 3 ,
75
- "metadata" : {},
75
+ "source" : [
76
+ " print(student1.name)\r\n " ,
77
+ " print(student1.roll_no)"
78
+ ],
76
79
"outputs" : [
77
80
{
78
- "name" : " stdout" ,
79
81
"output_type" : " stream" ,
82
+ "name" : " stdout" ,
80
83
"text" : [
81
84
" Prabhu\n " ,
82
85
" 1\n "
83
86
]
84
87
}
85
88
],
86
- "source" : [
87
- " print(student1.name)\n " ,
88
- " print(student1.roll_no)"
89
- ]
89
+ "metadata" : {}
90
90
},
91
91
{
92
92
"cell_type" : " markdown" ,
93
- "metadata" : {},
94
93
"source" : [
95
94
" ## *self* Keyword:\n " ,
96
95
" \n " ,
97
96
" Calls the attributes for current instance or object.\n " ,
98
97
" \n " ,
99
98
" Syntax: `self.attribute_name`"
100
- ]
99
+ ],
100
+ "metadata" : {}
101
101
},
102
102
{
103
103
"cell_type" : " markdown" ,
104
- "metadata" : {},
105
104
"source" : [
106
105
" ## Defining attributes in a class:\n " ,
107
106
" \n " ,
111
110
" Executes a set of code whenever a new object/instance is created.\n " ,
112
111
" \n " ,
113
112
" Defined by \\ _\\ _init\\ _\\ _ method."
114
- ]
113
+ ],
114
+ "metadata" : {}
115
115
},
116
116
{
117
117
"cell_type" : " code" ,
118
118
"execution_count" : 7 ,
119
- "metadata" : {},
120
- "outputs" : [],
121
119
"source" : [
122
- " class Student:\n " ,
123
- " def __init__(self): # default constructor\n " ,
124
- " self.roll_no = 0\n " ,
125
- " self.name = 'Name'\n " ,
126
- " # print('__init__ file')\n " ,
127
- " \n " ,
128
- " def study(): \n " ,
120
+ " class Student:\r\ n " ,
121
+ " def __init__(self): # default constructor\r\ n " ,
122
+ " self.roll_no = 0\r\ n " ,
123
+ " self.name = 'Name'\r\ n " ,
124
+ " # print('__init__ file')\r\ n " ,
125
+ " \r\ n " ,
126
+ " def study(self): \r \n" ,
129
127
" print('Studying....')"
130
- ]
128
+ ],
129
+ "outputs" : [],
130
+ "metadata" : {}
131
131
},
132
132
{
133
133
"cell_type" : " code" ,
134
134
"execution_count" : 8 ,
135
- "metadata" : {},
135
+ "source" : [
136
+ " st1 = Student()\r\n " ,
137
+ " st1.roll_no = 1\r\n " ,
138
+ " st1.name = 'Ravi'\r\n " ,
139
+ " print(f'Roll No: {st1.roll_no}, Name: {st1.name}')"
140
+ ],
136
141
"outputs" : [
137
142
{
138
- "name" : " stdout" ,
139
143
"output_type" : " stream" ,
144
+ "name" : " stdout" ,
140
145
"text" : [
141
146
" __init__ file\n " ,
142
147
" Roll No: 1, Name: Ravi\n "
143
148
]
144
149
}
145
150
],
146
- "source" : [
147
- " st1 = Student()\n " ,
148
- " st1.roll_no = 1\n " ,
149
- " st1.name = 'Ravi'\n " ,
150
- " print(f'Roll No: {st1.roll_no}, Name: {st1.name}')"
151
- ]
151
+ "metadata" : {}
152
152
},
153
153
{
154
154
"cell_type" : " code" ,
155
155
"execution_count" : 9 ,
156
- "metadata" : {},
157
- "outputs" : [],
158
156
"source" : [
159
- " class Student: \n " ,
160
- " def __init__(self, rn = 0, st_name = 'Name'): # Parametric Constructor\n " ,
161
- " self.roll_no = rn\n " ,
162
- " self.name = st_name\n " ,
163
- " # print('__init__ file')\n " ,
164
- " \n " ,
165
- " def study(): \n " ,
157
+ " class Student_details: \r \n" ,
158
+ " def __init__(self, rn = 0, st_name = 'Name'): # Parametric Constructor\r\ n " ,
159
+ " self.roll_no = rn\r\ n " ,
160
+ " self.name = st_name\r\ n " ,
161
+ " # print('__init__ file')\r\ n " ,
162
+ " \r\ n " ,
163
+ " def study(self): \r \n" ,
166
164
" print('Studying....')"
167
- ]
165
+ ],
166
+ "outputs" : [],
167
+ "metadata" : {}
168
168
},
169
169
{
170
170
"cell_type" : " code" ,
171
171
"execution_count" : 10 ,
172
- "metadata" : {},
172
+ "source" : [
173
+ " st2 = Student_details(2, 'Rahul')\r\n " ,
174
+ " print(f'Roll No: {st2.roll_no}, Name: {st2.name}')"
175
+ ],
173
176
"outputs" : [
174
177
{
175
- "name" : " stdout" ,
176
178
"output_type" : " stream" ,
179
+ "name" : " stdout" ,
177
180
"text" : [
178
181
" Roll No: 2, Name: Rahul\n "
179
182
]
180
183
}
181
184
],
182
- "source" : [
183
- " st2 = Student(2, 'Rahul')\n " ,
184
- " print(f'Roll No: {st2.roll_no}, Name: {st2.name}')"
185
- ]
185
+ "metadata" : {}
186
186
},
187
187
{
188
188
"cell_type" : " markdown" ,
189
- "metadata" : {},
190
189
"source" : [
191
190
" ## destructor:\n " ,
192
191
" Delete the current instance of class or object.\n " ,
193
192
" \n " ,
194
193
" Use \\ _\\ _del\\ _\\ _ method"
195
- ]
194
+ ],
195
+ "metadata" : {}
196
196
},
197
197
{
198
198
"cell_type" : " markdown" ,
199
- "metadata" : {},
200
199
"source" : [
201
200
" ## Some other methods:\n " ,
202
201
" \n " ,
211
210
" 0. \\ _\\ _eq\\ _\\ _ - equal\n " ,
212
211
" 5. \\ _\\ _getitem\\ _\\ _ - get a key from a iterable\n " ,
213
212
" 6. \\ _\\ _setitem\\ _\\ _ - set a value to the given key of iterable"
214
- ]
213
+ ],
214
+ "metadata" : {}
215
215
},
216
216
{
217
217
"cell_type" : " markdown" ,
218
- "metadata" : {},
219
218
"source" : [
220
219
" ## Private variables and methods:\n " ,
221
220
" \n " ,
227
226
" But if needed, use the following syntax:\n " ,
228
227
" \n " ,
229
228
" `obj._classname__attribute`"
230
- ]
229
+ ],
230
+ "metadata" : {}
231
231
},
232
232
{
233
233
"cell_type" : " markdown" ,
234
- "metadata" : {},
235
234
"source" : [
236
235
" ## Calling a method in another method inside the class:\n " ,
237
236
" \n " ,
238
237
" Use self keyword to call the function."
239
- ]
238
+ ],
239
+ "metadata" : {}
240
240
},
241
241
{
242
242
"cell_type" : " markdown" ,
243
- "metadata" : {},
244
243
"source" : [
245
244
" ## Definining run time class attributes:"
246
- ]
245
+ ],
246
+ "metadata" : {}
247
247
},
248
248
{
249
249
"cell_type" : " markdown" ,
250
- "metadata" : {},
251
250
"source" : [
252
251
" ## Methods of attributes:"
253
- ]
252
+ ],
253
+ "metadata" : {}
254
254
},
255
255
{
256
256
"cell_type" : " code" ,
257
257
"execution_count" : null ,
258
- "metadata " : {} ,
258
+ "source " : [] ,
259
259
"outputs" : [],
260
- "source " : []
260
+ "metadata " : {}
261
261
}
262
262
],
263
263
"metadata" : {
281
281
},
282
282
"nbformat" : 4 ,
283
283
"nbformat_minor" : 4
284
- }
284
+ }
0 commit comments