Skip to content

Commit dfb2643

Browse files
Classes Methods/Functions
1 parent e3640a8 commit dfb2643

File tree

1 file changed

+93
-1
lines changed

1 file changed

+93
-1
lines changed

README.md

+93-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
1-
# OOPs-Python
1+
# Object Oriented Programming in Python
2+
3+
------------
4+
## What do you understand by OOPs?
5+
-Object-Oriented Programming (OOP).
6+
The concept of OOP in Python focuses on creating reusable code.
7+
An object-oriented paradigm is to design the program using classes and objects.
8+
The object is related to real-word entities such as book, house, pencil, etc.
9+
The oops concept focuses on writing the reusable code.
10+
It is a widespread technique to solve the problem by creating objects.
11+
12+
------------
13+
01. [Classes]()
14+
15+
## NOTES
16+
------------
17+
#### 01. Classes
18+
19+
It is you can say a template.
20+
Classes are the building blocks in Object Oriented Programming.
21+
Classes can be seen as blueprints from which you create your Instances or Objects.
22+
In Python, classes are defined by the “Class” keyword
23+
24+
```
25+
class myClass():
26+
```
27+
------------
28+
------------
29+
30+
#### 02. Methods/Functions
31+
32+
- Inside classes, you can define functions or methods that are part of this class
33+
34+
```
35+
def method1 (self):
36+
print("OOPs")
37+
def method2 (self,someString):
38+
print ("Program-Method" )+ someString
39+
```
40+
. Here we have defined method1 that prints “OOPs”
41+
. Another method we have defined is method2 that prints “Program-Method”+ SomeString. SomeString is the variable supplied by the calling method
42+
43+
- Everything in a class is indented, just like the code in the function, loop, if statement, etc. Anything not indented is not in the class
44+
```
45+
class myClass():
46+
def method1 (self):
47+
print("OOPs")
48+
def method2 (self,someString):
49+
print ("Program-Method" + someString)
50+
```
51+
- [Note]
52+
- “self”
53+
- The self-argument refers to the object itself. Hence the use of the word self. So inside this method, self will refer to the specific instance of this object that’s being operated on.
54+
- Self is the name preferred by convention by Pythons to indicate the first parameter of instance methods in Python. It is part of the Python syntax to access members of objects
55+
------------
56+
------------
57+
#### 03. Objects
58+
59+
- How to make an object of the class?
60+
```
61+
obj = myClass()
62+
```
63+
64+
- How to call a method in a class?
65+
```
66+
obj.method1()
67+
obj.method2("Learning OOPs")
68+
```
69+
* Notice that when we call the method1 or method2, we don’t have to supply the self-keyword. That’s automatically handled for us by the Python runtime.
70+
* Python runtime will pass “self” value when you call an instance method on in instance, whether you provide it deliberately or not
71+
* Just work on non self arguments
72+
73+
- complete code
74+
```
75+
# Example file for working with classes
76+
class myClass():
77+
def method1(self):
78+
print("Guru99")
79+
80+
def method2(self,someString):
81+
print("Software Testing:" + someString)
82+
83+
84+
def main():
85+
# exercise the class methods
86+
obj = myClass ()
87+
obj.method1()
88+
obj.method2("Learning OOPs")
89+
90+
if __name__== "__main__":
91+
main()
92+
```
93+
------------

0 commit comments

Comments
 (0)