Loading…
A class is a blueprint for creating objects. An object is an instance of a class.
class Dog:
def __init__(self, name, age):
self.name = name
self.age = ageCreate an object
my_dog = Dog("Buddy", 3)
print(my_dog.name) # Buddy
__init__ is the constructor methodself refers to the current instanceCreate a class called Expense with:
__init__ method that takes description and amountCreate an expense and print its description and amount.
Downloading Python… (one-time, ~10 MB)
This runs entirely in your browser and is cached for next time.