Skip to content

Commit 6b1438e

Browse files
committed
Updates for OOPS
1 parent 2d3cc65 commit 6b1438e

File tree

4 files changed

+232
-142
lines changed

4 files changed

+232
-142
lines changed

OOPS.ipynb

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
65
"source": [
76
"# OOPS:\n",
87
"\n",
98
"Object Oriented Programming or OOP is working with classes and objects. It involves interaction between objects having various attributes.\n",
109
"\n",
1110
"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": {}
1313
},
1414
{
1515
"cell_type": "markdown",
16-
"metadata": {},
1716
"source": [
1817
"## Components:\n",
1918
"1. Class\n",
2019
"2. Object\n"
21-
]
20+
],
21+
"metadata": {}
2222
},
2323
{
2424
"cell_type": "markdown",
25-
"metadata": {},
2625
"source": [
2726
"## Class:\n",
2827
"\n",
@@ -33,75 +32,75 @@
3332
"Name of a class should start with an uppercase letter.\n",
3433
"\n",
3534
"Syntax: `class Class_name`"
36-
]
35+
],
36+
"metadata": {}
3737
},
3838
{
3939
"cell_type": "code",
4040
"execution_count": 1,
41-
"metadata": {},
42-
"outputs": [],
4341
"source": [
44-
"class Student:\n",
45-
" roll_no = int()\n",
42+
"class Students:\r\n",
43+
" roll_no = int()\r\n",
4644
" name = str()"
47-
]
45+
],
46+
"outputs": [],
47+
"metadata": {}
4848
},
4949
{
5050
"cell_type": "markdown",
51-
"metadata": {},
5251
"source": [
5352
"## Object:\n",
5453
"\n",
5554
"It is an instance of a class.\n",
5655
"\n",
5756
"Syntax: `obj_name = Class_name()`"
58-
]
57+
],
58+
"metadata": {}
5959
},
6060
{
6161
"cell_type": "code",
6262
"execution_count": 2,
63-
"metadata": {},
64-
"outputs": [],
6563
"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",
6967
"student1.name = 'Prabhu'"
70-
]
68+
],
69+
"outputs": [],
70+
"metadata": {}
7171
},
7272
{
7373
"cell_type": "code",
7474
"execution_count": 3,
75-
"metadata": {},
75+
"source": [
76+
"print(student1.name)\r\n",
77+
"print(student1.roll_no)"
78+
],
7679
"outputs": [
7780
{
78-
"name": "stdout",
7981
"output_type": "stream",
82+
"name": "stdout",
8083
"text": [
8184
"Prabhu\n",
8285
"1\n"
8386
]
8487
}
8588
],
86-
"source": [
87-
"print(student1.name)\n",
88-
"print(student1.roll_no)"
89-
]
89+
"metadata": {}
9090
},
9191
{
9292
"cell_type": "markdown",
93-
"metadata": {},
9493
"source": [
9594
"## *self* Keyword:\n",
9695
"\n",
9796
"Calls the attributes for current instance or object.\n",
9897
"\n",
9998
"Syntax: `self.attribute_name`"
100-
]
99+
],
100+
"metadata": {}
101101
},
102102
{
103103
"cell_type": "markdown",
104-
"metadata": {},
105104
"source": [
106105
"## Defining attributes in a class:\n",
107106
"\n",
@@ -111,92 +110,92 @@
111110
"Executes a set of code whenever a new object/instance is created.\n",
112111
"\n",
113112
"Defined by \\_\\_init\\_\\_ method."
114-
]
113+
],
114+
"metadata": {}
115115
},
116116
{
117117
"cell_type": "code",
118118
"execution_count": 7,
119-
"metadata": {},
120-
"outputs": [],
121119
"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",
129127
" print('Studying....')"
130-
]
128+
],
129+
"outputs": [],
130+
"metadata": {}
131131
},
132132
{
133133
"cell_type": "code",
134134
"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+
],
136141
"outputs": [
137142
{
138-
"name": "stdout",
139143
"output_type": "stream",
144+
"name": "stdout",
140145
"text": [
141146
"__init__ file\n",
142147
"Roll No: 1, Name: Ravi\n"
143148
]
144149
}
145150
],
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": {}
152152
},
153153
{
154154
"cell_type": "code",
155155
"execution_count": 9,
156-
"metadata": {},
157-
"outputs": [],
158156
"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",
166164
" print('Studying....')"
167-
]
165+
],
166+
"outputs": [],
167+
"metadata": {}
168168
},
169169
{
170170
"cell_type": "code",
171171
"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+
],
173176
"outputs": [
174177
{
175-
"name": "stdout",
176178
"output_type": "stream",
179+
"name": "stdout",
177180
"text": [
178181
"Roll No: 2, Name: Rahul\n"
179182
]
180183
}
181184
],
182-
"source": [
183-
"st2 = Student(2, 'Rahul')\n",
184-
"print(f'Roll No: {st2.roll_no}, Name: {st2.name}')"
185-
]
185+
"metadata": {}
186186
},
187187
{
188188
"cell_type": "markdown",
189-
"metadata": {},
190189
"source": [
191190
"## destructor:\n",
192191
"Delete the current instance of class or object.\n",
193192
"\n",
194193
"Use \\_\\_del\\_\\_ method"
195-
]
194+
],
195+
"metadata": {}
196196
},
197197
{
198198
"cell_type": "markdown",
199-
"metadata": {},
200199
"source": [
201200
"## Some other methods:\n",
202201
"\n",
@@ -211,11 +210,11 @@
211210
"0. \\_\\_eq\\_\\_ - equal\n",
212211
"5. \\_\\_getitem\\_\\_ - get a key from a iterable\n",
213212
"6. \\_\\_setitem\\_\\_ - set a value to the given key of iterable"
214-
]
213+
],
214+
"metadata": {}
215215
},
216216
{
217217
"cell_type": "markdown",
218-
"metadata": {},
219218
"source": [
220219
"## Private variables and methods:\n",
221220
"\n",
@@ -227,37 +226,38 @@
227226
"But if needed, use the following syntax:\n",
228227
"\n",
229228
"`obj._classname__attribute`"
230-
]
229+
],
230+
"metadata": {}
231231
},
232232
{
233233
"cell_type": "markdown",
234-
"metadata": {},
235234
"source": [
236235
"## Calling a method in another method inside the class:\n",
237236
"\n",
238237
"Use self keyword to call the function."
239-
]
238+
],
239+
"metadata": {}
240240
},
241241
{
242242
"cell_type": "markdown",
243-
"metadata": {},
244243
"source": [
245244
"## Definining run time class attributes:"
246-
]
245+
],
246+
"metadata": {}
247247
},
248248
{
249249
"cell_type": "markdown",
250-
"metadata": {},
251250
"source": [
252251
"## Methods of attributes:"
253-
]
252+
],
253+
"metadata": {}
254254
},
255255
{
256256
"cell_type": "code",
257257
"execution_count": null,
258-
"metadata": {},
258+
"source": [],
259259
"outputs": [],
260-
"source": []
260+
"metadata": {}
261261
}
262262
],
263263
"metadata": {
@@ -281,4 +281,4 @@
281281
},
282282
"nbformat": 4,
283283
"nbformat_minor": 4
284-
}
284+
}

0 commit comments

Comments
 (0)