Skip to content

Instantly share code, notes, and snippets.

@temmyzeus
Created January 22, 2022 15:34
Show Gist options
  • Save temmyzeus/418c117c6d8ef1d783b90b8192c71af7 to your computer and use it in GitHub Desktop.
Save temmyzeus/418c117c6d8ef1d783b90b8192c71af7 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
@classmethod
def from_list(cls, item_lst):
return cls(*item_lst) #notice this calls the class itself and initializes it
item = Item.from_list(['Burger', 2.55])
print('Name:', item.item_name, ', Price:', item.price)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment