1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "provenance" : [],
7
+ "authorship_tag" : " ABX9TyPE758gJN5gu/URgssTQbSu" ,
8
+ "include_colab_link" : true
9
+ },
10
+ "kernelspec" : {
11
+ "name" : " python3" ,
12
+ "display_name" : " Python 3"
13
+ },
14
+ "language_info" : {
15
+ "name" : " python"
16
+ }
17
+ },
18
+ "cells" : [
19
+ {
20
+ "cell_type" : " markdown" ,
21
+ "metadata" : {
22
+ "id" : " view-in-github" ,
23
+ "colab_type" : " text"
24
+ },
25
+ "source" : [
26
+ " <a href=\" https://colab.research.google.com/github/ambilisunil/python_basics/blob/main/Functions%26ClassesOOP.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type" : " markdown" ,
31
+ "source" : [
32
+ " # **function** is a reusable block of code that performs a specific task. Functions help in making the code more modular, readable, and reusable."
33
+ ],
34
+ "metadata" : {
35
+ "id" : " ad2tz8dFzvzM"
36
+ }
37
+ },
38
+ {
39
+ "cell_type" : " markdown" ,
40
+ "source" : [
41
+ " DEFINE FUNCTION :using **def**"
42
+ ],
43
+ "metadata" : {
44
+ "id" : " 3-jop9ASz1nC"
45
+ }
46
+ },
47
+ {
48
+ "cell_type" : " code" ,
49
+ "execution_count" : 1 ,
50
+ "metadata" : {
51
+ "colab" : {
52
+ "base_uri" : " https://localhost:8080/"
53
+ },
54
+ "id" : " Q9EgFXFGzc4K" ,
55
+ "outputId" : " c6ab2661-41bd-4afa-ac98-dee904a0edf6"
56
+ },
57
+ "outputs" : [
58
+ {
59
+ "output_type" : " stream" ,
60
+ "name" : " stdout" ,
61
+ "text" : [
62
+ " enter the first number2\n " ,
63
+ " enter the second number3\n " ,
64
+ " 5\n "
65
+ ]
66
+ }
67
+ ],
68
+ "source" : [
69
+ " def add(x,y):\n " ,
70
+ " print(x+y)\n " ,
71
+ " x=int(input(\" enter the first number\" ))\n " ,
72
+ " y=int(input(\" enter the second number\" ))\n " ,
73
+ " add(x,y)"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type" : " markdown" ,
78
+ "source" : [
79
+ " # **CLASSES**\n " ,
80
+ " a class is a blueprint for creating objects. It defines properties (**attributes**) and behaviors (**methods**).\n " ,
81
+ " **self** is like this\n " ,
82
+ " \n " ,
83
+ " \n "
84
+ ],
85
+ "metadata" : {
86
+ "id" : " Qm1HMdXV0m0M"
87
+ }
88
+ },
89
+ {
90
+ "cell_type" : " code" ,
91
+ "source" : [
92
+ " class Color:\n " ,
93
+ " name=\" orange\" #attribute\n " ,
94
+ " index=1 #attribute\n " ,
95
+ " \n " ,
96
+ " def pFun(self): #method\n " ,
97
+ " print(self.name)\n " ,
98
+ " print(self.index)\n " ,
99
+ " \n " ,
100
+ " instance =Color()\n " ,
101
+ " instance.pFun()\n " ,
102
+ " \n " ,
103
+ " \n "
104
+ ],
105
+ "metadata" : {
106
+ "colab" : {
107
+ "base_uri" : " https://localhost:8080/"
108
+ },
109
+ "id" : " FdzPv1Qt1DTM" ,
110
+ "outputId" : " 78aed214-dc4c-4151-f0f2-671f2c21f051"
111
+ },
112
+ "execution_count" : 4 ,
113
+ "outputs" : [
114
+ {
115
+ "output_type" : " stream" ,
116
+ "name" : " stdout" ,
117
+ "text" : [
118
+ " orange\n " ,
119
+ " 1\n "
120
+ ]
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "cell_type" : " markdown" ,
126
+ "source" : [
127
+ " # Class with instalization"
128
+ ],
129
+ "metadata" : {
130
+ "id" : " jGIM69Ha19Nr"
131
+ }
132
+ },
133
+ {
134
+ "cell_type" : " code" ,
135
+ "source" : [
136
+ " class Color:\n " ,
137
+ " name=\"\"\n " ,
138
+ " index=1\n " ,
139
+ " \n " ,
140
+ " def __init__(self,name,index=\" a\" ): # like constructor\n " ,
141
+ " self.name=name\n " ,
142
+ " self.inex=index\n " ,
143
+ " \n " ,
144
+ " def pFun(self):\n " ,
145
+ " print(self.name)\n " ,
146
+ " print(self.index)\n " ,
147
+ " \n " ,
148
+ " instance = Color(\" arul\" ,\" 1\" )\n " ,
149
+ " instance.pFun()\n " ,
150
+ " \n "
151
+ ],
152
+ "metadata" : {
153
+ "colab" : {
154
+ "base_uri" : " https://localhost:8080/"
155
+ },
156
+ "id" : " dKzXLnTS2CcQ" ,
157
+ "outputId" : " 84f95f1b-ec21-4f14-c11a-bea786b6f02d"
158
+ },
159
+ "execution_count" : 17 ,
160
+ "outputs" : [
161
+ {
162
+ "output_type" : " stream" ,
163
+ "name" : " stdout" ,
164
+ "text" : [
165
+ " arul\n " ,
166
+ " 1\n "
167
+ ]
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ "cell_type" : " markdown" ,
173
+ "source" : [],
174
+ "metadata" : {
175
+ "id" : " nn5FoE3C2CKZ"
176
+ }
177
+ }
178
+ ]
179
+ }
0 commit comments