-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop03.py
More file actions
25 lines (18 loc) · 645 Bytes
/
oop03.py
File metadata and controls
25 lines (18 loc) · 645 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
# creating a class
class Item:
# init is called automatically when an instance is created
def __init__(self, name, price, quantity):
print(f"An instance is created with name: {name}")
self.name = name
self.price = price
self.quantity = quantity
def calculate_total_price(self, price, quantity):
return price * quantity
item1 = Item("phone", 100, 5) # creating an instance of the Item class
item2 = Item("Laptop", 1000, 6) # creating another instance of the Item class
print(item1.name)
print(item2.name)
print(item1.price)
print(item2.price)
print(item1.quantity)
print(item2.quantity)