#18 - Property Methods

#18 - Property Methods

By Ifeanyi Omeata


Topics:


1. Property Methods


1. Property Methods


>>Return to Menu



class Employee():
    raise_amt = 1.04

    def __init__(self, first, last):
        self.first = first
        self.last = last

    @property
    def email(self):
        return '{}.{}@gmail.com'.format(self.first.lower(), self.last.lower())

    @property    
    def fullname(self):
        return '{} {}'.format(self.first, self.last)

    @fullname.setter
    def fullname(self, value):
        first,last = value.split(' ')
        self.first = first
        self.last = last

    @fullname.deleter
    def fullname(self):
        print(f'Deleted {self.fullname}')   
        self.first = None
        self.last = None

emp1 = Employee('Mike','Smith')

emp1.fullname = 'Ada Curry'
#del emp1.fullname

print(emp1.first)
print(emp1.email)
print(emp1.fullname)

#End


Hope you enjoyed this! :) Follow me for more contents...


Get in Touch:
ifeanyiomeata.com

Youtube: youtube.com/c/IfeanyiOmeata
Linkedin: linkedin.com/in/omeatai
Twitter: twitter.com/iomeata
Github: github.com/omeatai
Stackoverflow: stackoverflow.com/users/2689166/omeatai
Hashnode: hashnode.com/@omeatai
Medium: medium.com/@omeatai
© 2022