forked from spierre91/medium_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_python_tutorial.py
More file actions
44 lines (33 loc) · 987 Bytes
/
Copy pathclasses_python_tutorial.py
File metadata and controls
44 lines (33 loc) · 987 Bytes
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
36
37
38
39
40
41
42
43
44
#manually set attributes
class Spotify_User:
pass
user_1 = Spotify_User()
user_2 = Spotify_User()
user_1.name = 'Sarah Phillips'
user_2.name = 'Todd Grant'
user_1.email = 'sphillips@gmail.com'
user_2.email = 'tgrant@gmail.com'
user_1.premium = True
user_2.premium = False
print(user_1)
print(user_2)
print(user_1.name)
print(user_2.name)
#set attributes use initialization method
#define an additional method
class Spotify_User:
def __init__(self, name, email, premium):
self.name = name
self.email = email
self.premium = premium
def isPremium(self):
if self.premium:
print("{} is a Premium User".format(self.name))
else:
print("{} is not a Premium User".format(self.name))
user_1 = Spotify_User('Sarah Phillips', 'sphillips@gmail.com', True)
user_2 = Spotify_User('Todd Grant', 'tgrant@gmail.com', False)
print(user_1.email)
print(user_2.email)
user_1.isPremium()
user_2.isPremium()