Loading…
Class attributes are shared by all instances:
class Dog:
species = "Canis familiaris" # Class attribute
def __init__(self, name):
self.name = name # Instance attributedog1 = Dog("Buddy")
dog2 = Dog("Max")
print(dog1.species) # Same for all dogs
print(dog2.species) # Same value
Create an Expense class with:
currency = "USD"description, amountPrint the currency and both expense details.
Downloading Python… (one-time, ~10 MB)
This runs entirely in your browser and is cached for next time.