Another very distinct feature of Python, that is the Python Act property.
So what is your property, how to use it in python coding?
So let us give you one demonstration, one sample code, its execution, its explanation to describe
what is the property of Python.
The use of property in about Python programming has made the object oriented programming more easy in
Python.
So now let us go into the demonstration of the use of the property.
So here the Web defined one class.
The name of the class is temperature Celsius.
So there is a temp Celsius.
It is having one constructed here and we are passing one parameter temperature with the default argument
is negligible digital.
And here we are having this self underscore temperature, physical temperature.
So this instance biddable underscore temperature underscore indicates that this temperature is under
the microscope and is getting initialized with this input argument, input parameter.
That is the temperature.
And here we are having one method that is a convert to Fahrenheit, which will convert this respective
sun centigrade temperature to the following night here to it having two methods.
One is a guitar method that is a good temperature and another one is a certain method.
There is a set temperature guitar method will bring this text and it will return the respective value
in the temperature.
And the set method will check that the value which will be passed as input argument is less than minus
273 or not.
If it is so, it will raise one error that is evaluated with this respective message.
Otherwise it will bring this message and initialize this temperature with this new value which will
be passed as the input argument.
So now here we are going to have our property.
Property is nothing but one building function which creates and returns the property object.
The basic method signature is about if it is to null and then it is to Deunan.
And then if there is none and Doc is none now, what does it get?
It get is nothing but a function to get the value of the attribute, if it is a function to set the
value of the atiba.
So there is a split.
So if it is a function to get the value of that attribute, that is a greater method.
If it is nothing but a function to set the value of that, there is a certain method if there is a function,
to delete that attribute and doc is nothing but one string, which is like a comment here.
So now it is a particular property has got three methods.
There is a getter setter and delete, so three methods are there.
So here you are defining one and empty property.
So is that impression is a value property and then assigned to get so temperature is equal to temperature,
got getter get temperature.
So get the impression this particular method then we are passing this one as get temperature then assign
upset.
So temperature is equal to temperature.
Grasset set temperature.
So this method will be set as a set temperature.
So now we are going for C is equal to temp Celsius fight.
So C is that new object of the class that is that temp Celsius five.
So this fight will be assigned to this temperature, this particular message will get printed on the
screen and then we're having this one self understocked underscore temperature.
There is a private school temperature is the temperature.
So now let me go for the execution.
You can find that assigning temperature value, that means this constructor has got executed.
So the next one is that print siddharta temperature.
So whenever we are trying to print the value of the temperature, so actually when executing the guitar
method, so getting temperature value, so this particular message should be printed and then it will
return the temperature value.
So as a result of that, as we have, we have called this one from this print method.
So this fight will get printed before that, getting temperature value is also printed.
So now C temperature is equal to 100.
So now this 100 will be assigned.
So we are calling actually the set temperature because we we're setting this temperature so that temperature
will be called by default automatically because it has been set to the property.
There is a built in function and this value will be passed.
And here we are past the value that is 100.
So that's right.
If the value is less and less than minus 273, this condition is not getting through.
So the print setting temperature value, this message will be printed is it has got printed here and
now the value will be assigned to the temperature.
So now when you are again printing this C temperature, so you are getting the we are getting this particular
get temperature method is getting cold.
So getting temperature value and a self-taught underscore temperature will be returned.
And as a result of that, we are getting this one hundred.
So now see, we are making this one as a minus three hundred.
So now what will happen in this case?
The value error will be raised because it is lesser than minus 273, so minus three hundred is less
than 273.
So that is why it is producing that that elevator.
So there is a temperature below minus 273 is not possible.
So that message is getting printed here.
So in this way, we have shown that how this property is getting.
He was here.
OK.
Instead of writing this disrespectful statements, I'm just making the comment I can do the same, just
writing a single statement here.
So there is a temperature is the property.
So the first argument will be if I'm passing that one as a good barometer, the second argument is our
upset.
So we are passing this perimeter that is opposite temperature.
So now this these are the a method is a certain method for if I'm going to get the same output here
now, see if I go on printing.
Princi Daudt underscored underscore.
Did this underscore, underscore, so if you go on printing and finding that I'm fine, I'm finding
one couple is getting printed where this all the instance variable defined in this class is getting
printed with the respective help.
So it is a key value pair.
So just if I go forward to finding out of the one.
Another instance, variables set up with a 500.
If I go to court here, you can find that we're having temperature with a 110 temp with the value 500.
So anybody we bring in some some member variable from this object, actually we're accessing that is
the object named DOT, underscored, underscore, DECT, underscore, underscore.
So if I do not want to print all of them, I can print only the temperature here.
So I shall go for this temperature.
So I can bring only the temperature here, you can find that.
It will bring down the value 100, so if I go on printing only the temp, so that can also be done.
So I think that will bring 500 here.
OK, so that has printed to 500.
OK, now let us concentrate on this property.
So we are having two ways to to have this building function.
So that is that one is the temperature is the property get temperature.
There is a greater than the temperature.
There is a set of metal you can pass.
Otherwise we can make and one empty property object and then we can go for this temperature to get there
and temperature for Setar to give the name of the two parties the name of the greater method and a certain
method respectively.
So let us come to the next example here.
So here you see here, here we are having this in it that is constructed here, the name of the class
in Celsius to perform tonight.
It is converting the Celsius temperature to the far right here.
We're having this at the rate of property is the aderet.
And then we are having this property.
So obviously, this particular this particular after writing this one, we are writing only the temperature.
You see the method name is temperature.
We are not going for the respective GETER setting temperature or temperature methods.
So anybody writing this at the rate of property, that means it is known as the guitar method.
And anybody who are writing this at the rate of temperature Dorsetshire, that means it is the same
method.
So I need not to bother for this set temperature or get temperature will be having the method name as
temperature here.
You see, I didn't do any kind of changes in the respective function bodies, so now C is equal to Celsius
five.
So princi temperature.
So I'm just executing this code here.
So you see here that the method is are getting value is getting printed.
So now you see the C temperature.
That means this particular method is getting printed.
There is a greater method.
And here C, I didn't write anything, anything that is a get underscore or something.
I've given the function name as the temperature.
Only Adelita property will be there, will be downloaded and given at the first and next we are having
the seed or temperature is equal to 100.
So what will happen here.
It is a setting, value is getting cold and then whenever we are printing this print, see the temperature.
Then there's this.
One hundred is getting printed after printing this message getting through.
So here you see here we are calling the property method.
We are just using this at the rate of property and at the rate of temperature, etc..
So using this particular Adelaida property and other top temperature Dorsetshire, we are just defining
that which is the method and which is the getter method.
So as a result of that, in our object oriented coding, I need not to call the respective functions
by the names I can easily use.
That is a seed temperature for the printing or C the temperature is one hundred for the assigning.
So accordingly, the veterans letter methods are getting cold.
So this is a nice usage of this property method in our python coding to make the object oriented programming
much, much simpler.
Thanks for watching this video.