Best Way to Learn Python in 2020 : Episode 2
Hey Guys In this episode you are going to learn Object-oriented programming for python before that let's see what is OOP and why OOP is essential for learning any programming language
Feeling excited !! Let's get started!!
What is mean by OOP?
Object-oriented programming: As the name suggests, Object-Oriented Programming or OOPs refers to languages that use objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
Everything in Python is an object.
You either heard this already, or you are destined to hear about it 🙂
But wait a minute, what exactly is an object?
There are many different ways, models, or paradigms to write computer programs.
One of the most popular programming paradigms is called object-oriented programming
In object-oriented programming, an object refers to a particular instance of a Class.
And a Class is like a blueprint of the state and actions that an object can take.
For example, in Python, a Person Class might look something like this.
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def get_name(self):
return self.name
The class declared above describes the state and actions of any Person object.
For example, any Person object will have a name and an age. These two fields are what determines the state of the object.
In OOP’s terminology, naWe call get_name a method.
And this method, in addition to any other methods that we define, is what determines the object’s actions.
In other words, a Python object has attributes and methods that are defined in the object’s Class.
Here’s how to create a Person object
>>> p = Person('Alice', 22)
>>> p.get_name()
'Alice'
Object-oriented programming is essentially one way of structuring and designing your code.
However, I want you to understand that it is not the only way, and it is not necessarily the best way.me and age are called the object attributes.
In order to learn OOP in Python, you need to progress through a few steps.
Step 1: Learn the concepts of OOP
As I mentioned earlier, OOP is a programming paradigm, a way of structuring and designing your code.
OOP concepts are not exclusive to Python so the concepts you will learn will easily transition to any other programming language.
Some examples of these concepts are inheritance, encapsulation, and polymorphism.
So make sure you understand these concepts at an abstract level first before you jump into Python’s OOP.
Step 2: Learn about Python’s Classes and Objects
In this step, you need to apply the abstract concepts you learned in the previous step but specifically in Python.
Get comfortable with writing Classes and creating Objects.
Write classes that inherit from other classes and investigate the attributes and methods of the objects created.
Step 3: Solve Python problems using OOP
This is a crucial step.
In this step, you want to learn how to use OOP to design and structure your code.
And as a matter of fact, this step is more of an art than a science. That means the only way to get better is through practice, practice, and more practice.
Again keep solving more problems using Python, but try to structure your solutions in an object-oriented way.
The more you practice, the more you will feel at ease with OOP.
Hope you guys enjoyed this episode!!
Comments
Post a Comment