Introduction
Welcome to my 56th blog post on the Python coding journey. On day 56, I learned about the concept of OOP's i.e Object Oriented Programming in Python. I learnt the concept of object and classes in OOP's and also learned about the properties used in Object Oriented Programming i.e 'Encapsulation', 'Inheritance' and 'Polymorphism'. Let's dive into more details and understand the OOP's concept in Python.
So let's get started......
Object Oriented Programming
In Programming, there are two ways in which we write the code viz:
Procedural Programming
Object-Oriented Programming
Till now the way we were coding is a way of “Procedural Programming” approach, wherein we manually define multiple variables and their properties (methods). Now on day 56, I learned about Object Oriented Programming (OOP). The basic idea of object-oriented programming (OOP) in Python is to use classes and objects to represent real-world concepts and entities.
What is a Class?
It is a blueprint or template for creating objects.
The properties and methods that an object will have will be defined in the class.
The properties of an object are like features of the object. In technical terms, properties are the data or state of an object.
Methods are like the functions that an object can perform i.e in technical terms, methods are the actions or behaviors that an object can perform.
Example
Suppose there is a class called as a human being.
So for the human being his features or properties will be his body parts like eyes, ears nose, hands, legs, age, hair color etc. His functions or methods will be walking, dancing, playing, running etc.
What is an Object?
It is an instance of a class
It contains its own data and methods.
For example, you could create a class called "Person" that has properties such as name and age, and methods such as speak() and walk().
Each instance of the Class would be a unique object. In the above example, each object of 'Person' class will be unique with its own name and age, but they would all have the same methods to speak and walk.
What is Encapsulation?
One of the key features of OOP in Python is 'Encapsulation',
It means that the internal state of an object is hidden and can only be accessed or modified through the object's methods.
It helps in protecting the object's data and prevent it from being modified in unexpected ways.
What is Inheritance?
The next key feature of OOPs is 'Inheritance'.
It allows the new class to be created from the existing class and inherits the properties and methods of an existing class.
This allows a way for code reuse and makes it easy to create new classes that have similar functionality to existing classes.
What is Polymorphism?
It means that objects of different classes can be treated as if they were objects of a common class.
This makes it easy to write code and provides reuse of code that work with multiple objects and allows for greater flexibility.
Resources Used
You can watch the video of Day#56 by clicking on the below link 👇👇👇👇👇
Conclusion
Thanks, guys for going through this blog post. Concluding day 56th of my python coding journey, on day 56, I learned about Object-oriented Programming in Python that allows users to model real-world concepts and entities using classes and objects. I also learned about the properties of OOPs like encapsulating data, reusing code through inheritance, and writing more flexible code through polymorphism.
Thank you if you read this post and have found this post useful. I hope you have joined me and are enjoying my magical journey of Python coding. This is it for Day #56
See you in the next one.....
About Me
Hey Guys, I am Chintan Jain from CodeWithJain. I am a trader and content creator. I am also passionate about tech and hence wanted to explore the field of tech. I always wanted to learn to code so I watched many tutorials but procrastinated practicing coding. To get into the habit of coding consistently I am starting to BLOG with HASHNODE on daily basis.
I will document my coding journey from scratch and share my daily learnings in a blog post on HASHNODE. I hope you all will enjoy my content and my coding journey.
So what are you waiting for, smash the FOLLOW and LIKE buttons and follow along my coding journey, a step to create more beautiful digital products and empower people.