Posts

Showing posts from October, 2019

Let's Learn some Python Today

Python @property You will learn about Python @property; pythonic way to use getters and setters. Python has a great concept called property which makes the life of an object oriented programmer much simpler. Before defining and going into details of what @property is, let us first build an intuition on why it would be needed in the first place. An Example To Begin With Let us assume that you decide to  make a class  that could store the temperature in degree Celsius. It would also implement a method to convert the temperature into degree Fahrenheit. One way of doing this is as follows. script.py IPython Shell 1 2 3 4 5 6 class Celsius : def __init__ ( self , temperature = 0 ) : self . temperature = temperature def to_fahrenheit ( self ) : return ( self . temperature * 1.8 ) + 32 Run Powered by DataCamp We could make objects