Python is an amazing programming language and its capabilities for reducing large functions into few lines give ease to programmers for building complex applications. It allows programmers to design systems focused on real-world properties using a concept called Object-oriented programing, Whereas, procedural programming designed system performs the operations on data.
Object-oriented programming is the approach of performing the operations by creating objects that contain data and functions and then executing the required functions. If you want to understand this kind of programming then you have to get familiar with these properties:
Class: It is a user-defined type that contains variable instances and methods and acts as a blueprint for creating objects.
class ClassName: def __init__(self, x, y): self.x = x self.y = y def showFunction(self): print("value X: " + self.x) print("value Y: " + self.y) def changeXFunction(self, x): self.x = x
Object: It is an instance of the class which changes state or shows behaviour by invoking methods.
// create object with state object = ClassName(5, 10) // show behaviour object.showFuction() // change state object.changeXFunction(15)
Capabilities of class
- Polymorphism
- Encapsulation
- Inheritance
- Data Abstraction
To learn about these capabilities, use resources by clicking on the resources button.