class
KeywordPython 2.0+Beginner
Defines a new class (blueprint for creating objects)
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Dog: def __init__(self, name, breed): self.name = name self.breed = breed def bark(self): return f"{self.name} says Woof!" dog = Dog("Rex", "Labrador") print(dog.bark()) print(dog.name) print(dog.breed)
A class bundles data (attributes) and behavior (methods) together. __init__ runs when you create a new instance.
Try in PlaygroundTags
languagesyntaxcoreoopdatatype