Skip to content

Commit 529834e

Browse files
Constructors
1 parent b9a7143 commit 529834e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
00. [OOPs](https://github.com/Shikha-code36/Object-Oriented-Programming-OOPs-Python#what-do-you-understand-by-oops)
44
01. [Classes](https://github.com/Shikha-code36/Object-Oriented-Programming-OOPs-Python#01-classes)
55
02. [Methods/Functions](https://github.com/Shikha-code36/Object-Oriented-Programming-OOPs-Python#02-methodsfunctions)
6+
03. [Objects](https://github.com/Shikha-code36/Object-Oriented-Programming-OOPs-Python#03-objects)
7+
04. [Constructors](https://github.com/Shikha-code36/Object-Oriented-Programming-OOPs-Python#04-constructors)
68

79
------------
810
## What do you understand by OOPs?
@@ -78,10 +80,10 @@ obj.method1()
7880
# Example file for working with classes
7981
class myClass():
8082
def method1(self):
81-
print("Guru99")
83+
print("OOPs")
8284
8385
def method2(self,someString):
84-
print("Software Testing:" + someString)
86+
print("Program-Method" + someString)
8587
8688
8789
def main():
@@ -93,4 +95,16 @@ def main():
9395
if __name__== "__main__":
9496
main()
9597
```
98+
------------
99+
------------
100+
#### 04. Constructors
101+
102+
Constructors are generally used for instantiating an object. The task of constructors is to initialize(assign values) to the data members of the class when an object of the class is created. In Python the __init__() method is called the constructor and is always called when an object is created.
103+
104+
The __init__ method lets the class initialize the object's attributes and serves no other purpose. It is only used within classes.
105+
106+
```
107+
def __init__(self):
108+
# body of the constructor
109+
```
96110
------------

0 commit comments

Comments
 (0)