Setters Nad property function in the python :-
class Emploee:
def __init__(self,fname,lname):
self.fname = fname
self.lname = lname
# ye property easly access hogi jaab object se call karnege
# self.email = fname + lname +"@gmail.com"
# ye function apko property jaise acccess karna hai to aap @property ka use kar sakte hai
#
@property
def email(self):
if self.fname == None or self.lname == None:
return f"Please set firsst name and last using the setter function .... email is not set yet"
return f"{self.fname}.{self.lname}@vishalusrate.com"
# if you want to change the any of the property of the class you can change the using of the setters method
@email.setter
def email(self,other):
print("Printing statement is executiong....")
new_data = other.split("@")[0]
fname = new_data.split(".")[0]
lname = new_data.split(".")[1]
self.fname = fname
self.lname = lname
@email.deleter
def email(self):
self.fname = None
self.lname = None
# creating the object of the particular class
vishal = Emploee("Vishal","Usrate")
lakhan = Emploee("lakhan","Usrate")
# print(vishal.email)
vishal.fname = "Test"
vishal.lname = "Data"
# print(vishal.email)
vishal.email = "data.tata@cent.com"
print(vishal.fname)
del vishal.email
# vishal.email = "Test.bhai@gmail.com"
print(vishal.email)
Thanks you for commenting your questions. I will see question and respond you.