Decorator is a special kind of Funtion which returns another Function as output.
and '@property' Decorator is used upon a Class Method to return that Method as a String format. look at the code block .....
class Employee:
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
@property
def email(self):
return f"{self.fname}.{self.lname}@gmail.com"
Here, we don't need to call the 'email' Function as usual, like below..
google = Employee('alpha', 'bet')
em = google.email()
print(em)
Hence, we can just use it as a String. Because, the '@property' Decorator has coverted the 'email' Function to a Property. Then it will return anything, but we have to call that is a Attriubte not as a Function 🚫
code block:
google_employee = Employee('google', 'employee')
emp_mail = google_employee.email
print(emp_mail)
0 Comments