Biton or be approach that is object oriented programming approach.
Python is a mighty paradigm programming language as it supports different programming approach, and
one of the popular approaches to solve a programming problem is by creating objects.
And this is known as object oriented programming, that is, or B, so objects will be doing everything.
So that's why you will be defining objects and using objects, be writing our code.
And that is why, despite what is known as object oriented programming, language and object has two
characteristics.
The first one is the attributes or messages.
That is, what are the different values these attributes can hold and behaviors or methods which will
define that.
What are the different palmitate operations that we can carry out on these attributes and messages?
So let's take one example, so dog is an object, and it, as it has that name, age, height, weight,
color, are the attributes and barking, wagging and this running are the respective behaviors.
So the concept of object oriented programming in Python focuses on creating reusable codes that meets
once the code will be defined, will be written.
We can reuse that code as when required.
So reusability will be enhanced if you go for the object oriented programming, because whatever the
methods you are going to write, that can be used for any number of times.
So this concept is also known as dry.
That is, don't repeat yourself.
In Python, the concept of object oriented programming follows some basic principles.
So what are the principles where basically had three principles, that is the inheritance.
Next one is the encapsulation.
Next one is the polymorphism.
So a process of using details from a new class without modifying the existing class.
So the process of using details from a new class without modifying the existing class is known as the
inheritance where the reusability code is getting implemented.
That means there will be having one class from the class will be taking the respective methods and attributes,
respective messages and methods in another class, and we can go on adding some other methods and messages
as applicable.
Next one is the encapsulation that is hiding the private details of a class from other objects.
So class is nothing but a common blueprint for all the alike objects.
So that is known as a class and in case of encapsulation, it will hide those private details of a class.
And next one is a polymorphism.
That is a concept of using common operation in different ways for different data input.
So this is known as polymorphism.
Whenever multiple things are the same thing will have a different name.
Rather, I should say the same thing has got a different name, then we can call it as a polymorphic.
So that's that's why its concept of using the common operation in different ways by saying different
data input is known as a polymorphism.
So these are the main three pillars of object oriented programming.
So let us go for one demonstration, which will be showing you that how this python has become object
oriented.
In object oriented programming in Python, we define class and objects.
We know that instance of a class is known as an object.
An object consists of multiple different messages which will be holding different values and methods,
which will decide who will determine the palmitate operations that we can carry out on those messages.
Here we are defining one class.
The name of the class is mainboard and this class is having three different methods.
The first method is very special is underscored, underscore in it, underscore, underscore.
This method is known as constructed.
A constructor name will be will be Ollis underscored underscoring it underscore underscore irrespective
of the class name.
And it will have the prototype which will be having oneself as input argument.
So this self is actually denoting the object reference that was object which will be created under this
class.
And this is also known as this reference.
So this is this particular unit this constructed is having only one statement to get printed.
Also, we are having other methods, that is of what type, and we are having the method that is cancer
in whatever method is having this string to get printed.
And this cancer is also having this string to get printed here.
So in this way, we have declared the class body mainboard.
So now we are going for this might Barat.
And here we are having one instance, Biddable Spice's, which is having this string that is a bar here,
and this is of a constructor which will print this respective message.
And here we are defining two instance variables separately.
One is name and age, which will get initialized with this input parameters.
We are having another method that is that can sing.
And this from this method are returning one string.
And this is a string which will go on returning.
And you see here we are passing this name as a placeholder content and this song as a placeholder content.
So in this way, we have defined this my better class here.
So now we are having the next class that is a penguin.
This my penguin is inheriting the class mainboard.
You can easily recall that this my bird was a class.
And if you go on executing, you can find that it is having no method has been called from this mainboard
class.
So that is why it is producing no output, only the mere declaration we are having.
And now we are having this my parrot and this might I have executed.
So no, it has been observed.
Now this is my penguin.
This is one class which is inheriting properties from my part.
So my bad properties means these properties will get inherited.
We should know that when we are having one method or one message preceded by the underscore means,
it is a private under the private and double undertaken means it is strictly private.
Private members cannot be accessed from outside of the class.
So this is my penguin, which is inheriting my bird class and it is having their respective constructor
here.
And who is calling the best class constructor?
The best class means that my bad my bad constructor can only be called using dot underscored underscore
in it underscore underscore method.
That means we are calling the best class constructor.
This super method is actually denoting the best class name.
And what about the name of the best class it can be for using this super method and it is calling the
best class constructor in the local function.
But we are writing this that Pinguin is ready.
Next one.
You are having this.
Who is this is a respective string to get printed can run.
These are the method, the respective string will get printed here.
So in this way we have defined my pinguin that this we have defined the my pinguin, which is inheriting
mainboard class here.
OK, so I'm writing this one as my pen.
That will be better.
So my penguin class inheriting the attributes from my bird class here.
So now let us go for that instantiation.
That means we shall declare some instance of the class in sense of the class means we're defining the
object of the class here.
The class name is my parrot.
So we are calling the constructor so empty.
One that is a parrot.
One is equal to my parrot.
My better one will be the name and then will be given as the value for this here.
So you can find that it is will be passed and the name will be passed here.
So that's why we're having this.
My parrot one is a name and ages, then my parrot too is the name.
Pipetting is the edge here.
So in this way you have defined two objects.
What is important and that one is mprda it is actually denoting my parrot one on my part or two.
So now to access the class attributes we can write in this way.
Impey one is eight so we can go for format and now be one dot class dot spaces so we can have this one.
So this is nothing but one message.
I think one member, whether we define that is suspicious and it is not under private because we haven't
given any kind of underscore single or double before the is.
So it is under the public school can be accessed from the outside.
So that's why we're having this empty one dot class dot pieces.
And now had we are having this is also a also the placeholder is there and format importunate class
dot businesses.
So now we are going for this.
That is an instance aquiver.
So now we are going for this empty one dot name, an empty one dot aides are going to get printed using
this particular placeholders and dot format method so we that can string that windshear.
We're having one method that is accounting.
This can think you can find that this can be defined here.
So it is our method is can sing.
This particular method requires one string as input document the aspect of the song name.
So here we are passing this, this IRP so that is the can sing is taking this particular string as input
document and now we're having this.
So let me go for the execution for the better clarity.
You can find that.
So my parrot class constructor is executing, so whenever we are calling this particular constructor
to instantiate instance variables of this, my parrot, then my parrot class constructed is executing
two times because we have defined two objects here.
So just going to this, my party can easily find that he had written this my parrot class constructor
is executing.
So this line is producing the requesting as output and hear the name and age are getting initialized
with this input parameters name and Agere so he can get it.
OK, next we're going for this.
That is the empty one is a you see MPLX one is a bird and MP two is also a is also a bird.
Because here this business we initializes species with the string Baade here.
OK, now we are printing this empty one name and one dot age, and it is giving the value as to my parrot.
One is my favorite, one is 10 years of age.
I mean, two is 15 years of age.
So head MPU, MP one, that name is getting my parrot.
One, we give that give that name and age.
You have passed as ten.
So they are getting printed and in this case to not name is getting instantiated with this my parrot
to an MP 2.8 is getting instantiated with this whuppin.
So accordingly we are getting the required outcome.
So now we are having this can sing.
So this is this particular method is producing this outputted.
So here you can find that here we are going to have our output.
That is my parrot.
One can sing chirp.
And here to see we have this particular string, C.H. IRP, there is a chart here.
So this particular string is getting printed here because if you go to this can sing method, you can
easily find that here we wrote this one, that is the respective name can sing this song here that this
song has got initialized with the string scharper.
OK, now we are going for another one, so we are going to define one object under the glass, my pinguin.
So now this is our class might be and it has got the method that is.
Who is this?
And can run.
These are respective strings are going to get printed using the printed function.
So you wonder who is this busy one that can swing and bid you one dot can run here so you can find that
this particular class, my pinguin, is having the instance functions, that that is our who is this
and can run this mainboard.
This my board that already defined.
Here it is.
I mean the method what type and can swim.
So as a result of that this my pinguin is inheriting my part.
So as it is that my body's defined the methods, the different methods can has got inherited into my
pinguin so they can be accessed.
So here to abuse this Bidgee one that can swim and pigeon dot can run here, you can easily find that
inboard we're having this can swim and in Penguin we're having this can run.
But from the might be an object I can access both can run and can swim.
Exactly.
So now you can find this one.
So if, if we execute then Behnken is ready.
This particular message is getting printed from the constructor.
So here we are having the constructor here to operate in this.
Pinguin is ready and now we're having this.
I can swim, I can run faster.
This I can swim.
I can run faster.
Has come from this can run, which is defined within this my being class, but as it is inheriting my
weight class.
So from my part I can swim now that is I can swim.
This particular message is getting printed as we call this can swim method.
So I think from this particular example, you are getting this idea how to define one class, how to
define one object, what is inheritance?
And when the inheritance is taking place, then how to access and the best class members from the class
objects.
So I think you are getting this idea.
This is a record upward.
We are going to get printed.
So now let us go for it on the part.
So here you are defining one class that is a personal computer to show you that what is that encapsulation
in subject encapsulation, the member variables and the member functions will get encapsulated within
the class.
So in it, as I discussed earlier, that in it is nothing but one constructed here.
This Max computer prize is nothing but one instance variable which has got initialized with the value.
Twenty thousand.
We're having another method that is a myself and having the method set max computer price so you can
find that these are respective bodies are there and set max computer price is taken this price as input
parameter and that price is instantiating or initializing max computer price.
That is the instance variable.
It is this personal computer class where you find one object, the name of the object is busy, busy
myself.
So this method is going to get executed.
President Max Computer Prize.
We've just upgraded that one using 30000 here.
So beside myself, you see the respective method will get printed and set.
Max computer prize.
Again, we're calling this set Max computer price method, passing this price as input document input
parameter, which will initialize this Max computer prize in standard variable.
So again, if you go on printing myself, then obviously I shall be getting this updated prize here.
So now let me go for the execution.
You can find that selling price is twenty thousand.
Initially, the selling price will be 20000 because max price within the constructor got initialized
with 20000.
So whenever we call this out myself.
So Max Price has got printed as 20000.
Opta that we did some update directly using the instance biddable.
Then we did some update using this set Max computer price method and here the price has become 30000.
So MYSEL has printed the selling price at 30000 after doing the opposite with the 40000 pieces that
might sell.
This method is printing selling price as 40000.
So you are getting this idea how these glasses are having the respective messages and the methods encapsulated
within the class.
So I think now you are getting the idea in case of Python, how we can implement object oriented language
features.
Thanks for watching this video.