PYTHON OBJECT-ORIENTED
Object-oriented programming is a programming paradigm in which are based on the concept of Object. Python also supports some features of Object-oriented programming (OOP). In this post, We will learn about these features.
To access method of a class we have to
Object-oriented programming is a programming paradigm in which are based on the concept of Object. Python also supports some features of Object-oriented programming (OOP). In this post, We will learn about these features.
Python OOPS Concept
- Class
- Object
- Method
- Inheritance
Class
In programming languages class provide a way to bundle data and functionality together. The simplest form of class definition syntax will look like
class ClassName():
< statement - 1 >
.
.
.
< statement - n >
Exampleclass Calculate():
x = 1
Object
An object is an instance of a class. Syntax to create an object of above class Calculate is
objectName = ClassName():
Exampleobj = Calculate()
We can access variable x with the syntax.
objName.VariableName
obj.x
Method
class Calculate():
x = 1
def fun (self):
print ('This is a method')
Keyword self refer to an object.To access method of a class we have to
- Create an object of class
- Access the method
For example in order to access fun method of Calculate class
obj = Calculate() #Created an Object, Step 1
obj.fun() # Accesing method, Step 2
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment