-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-classes.py
More file actions
46 lines (37 loc) · 1.23 KB
/
10-classes.py
File metadata and controls
46 lines (37 loc) · 1.23 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
35
36
37
38
39
40
41
42
43
44
45
# A class is like a blueprint for creating objects. An object has properties and methods(functions) associated with it. Almost everything in Python is an object
# Create class
class User:
def __init__ (self, name, email, age):
self.name = name
self.email = email
self.age = age
def greeting(self):
return f'My name is {self.name} and I am {self.age}'
def has_birthday(self):
self.age +=1
class Customer (User):
def __init__ (self, name, email, age):
self.name = name
self.email = email
self.age = age
self.balance = 0
def set_balance(self, balance):
self.balance = balance
def greeting(self):
return f'My name is {self.name} and I am {self.age} and I owe {self.balance}'
# Init user object
steve = User (' Steve Kelvin', 'kelvin@yahoo.com', 34)
print(steve.name)
# Edit property
steve.name = "Steve Williams"
print(steve.name)
janet = User ('Janet Jones', 'janet@yahoo.com', 34)
print(janet.name)
print("Janet's birthday is ", janet.has_birthday())
print(janet.greeting())
# Init customer
john = Customer ("John Meyer", 'john@yahoo.com', 32)
john.set_balance(324.32)
# print(john.set_balance)
# print(john.name)
print(john.greeting())