Skip to content

Instantly share code, notes, and snippets.

@temmyzeus
Created January 22, 2022 15:24
Show Gist options
  • Save temmyzeus/85154c6a6b55025de4be60ca8090863d to your computer and use it in GitHub Desktop.
Save temmyzeus/85154c6a6b55025de4be60ca8090863d to your computer and use it in GitHub Desktop.
class Item:
# this is a class variable
percent_off = 0.1
def __init__(self, item_name, price):
self.item_name = item_name
self.price = price
# a class method taking in 1 argument
@classmethod
def raise_percent_off(cls, new_percent_off):
cls.percent_off = new_percent_off
burger = Item(item_name='burger', price=2.55)
# print out the percent_off
print('Orignal Percentage Off:', burger.percent_off)
# Item.raise_percent_off(0.3)
# 0R
burger.raise_percent_off(0.3)
# print out the percent_off after the altering
print('Edited Percentage Off:', burger.percent_off)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment