-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection_04.py
More file actions
34 lines (26 loc) · 1.02 KB
/
section_04.py
File metadata and controls
34 lines (26 loc) · 1.02 KB
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
# # Protected, but only by convention
# class User:
# def __init__(self, username, email, password):
# self.username = username
# self._email = email
# self.password = password
# def clean_email(self):
# return self._email.lower().strip()
# user_01 = User("Dave", "aaa@corp.com", "abc")
# user_02 = User("Bob", " BBB@corp.com ", "abc")
# for u in [user_01, user_02]:
# print(u._email) # Breaks convention, but works
# print(u.clean_email()) # Expected way
# Actually protected (Private), use double underscore
class User:
def __init__(self, username, email, password):
self.username = username
self.__email = email
self.password = password
def clean_email(self):
return self.__email.lower().strip()
user_01 = User("Dave", "aaa@corp.com", "abc")
user_02 = User("Bob", " BBB@corp.com ", "abc")
for u in [user_01, user_02]:
# print(u.__email) # Doesn't work
print(u.clean_email()) # Expected way