forked from kayartaya-vinod/2018_08_PHILIPS_ADV_PYTHON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex04.py
35 lines (25 loc) · 698 Bytes
/
ex04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Person:
def __init__(self, **kwargs):
self.__name = kwargs.get('name')
self.__age = kwargs.get('age')
self.__city = kwargs.get('city', 'Bangalore')
self.__email = kwargs.get('email')
def __str__(this):
return 'name={}, age={}, city={}, email={}'.format(
this.__name, this.__age, this.city, this.__email)
# getter / accessor
@property
def city(self):
return self.__city.upper()
# setter for city
@city.setter
def city(self, value):
if type(value) != str:
raise ValueError('City must be a str')
self.__city = value
def main():
p1 = Person(name='Vinod', age=45, email='vinod@vinod.co')
p1.city = 'Bengaluru'
print(p1)
if __name__ == '__main__':
main()