Skip to content

Instantly share code, notes, and snippets.

@temmyzeus
Created January 22, 2022 14:51
Show Gist options
  • Save temmyzeus/b7bb2805a18e5ebdc63d45cbb3b80321 to your computer and use it in GitHub Desktop.
Save temmyzeus/b7bb2805a18e5ebdc63d45cbb3b80321 to your computer and use it in GitHub Desktop.
class Item:
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
# this is an instance method taking in no arguments
def buy_item(self):
print(f'{self.item_name.title()} is being bought for ${self.price}')
# instance method taking 1 argument
def increase_price(self, new_price):
print(f'{self.item_name.title()} price is increased to ${new_price} from ${self.price}')
self.price = new_price
burger = Item(item_name='burger', price=2.55)
burger.increase_price(3.50)
burger.buy_item()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment