OOP lets you model real-world things with classes and objects. It helps organize code, reuse it, and build complex programs more easily.
A class
is a blueprint to create objects. It defines attributes (data) and methods (functions) that belong to the object.
This example defines a Dog
class with a method that makes the dog "bark".
This example adds an age
attribute and a method that prints info about the dog.
self
to access or modify attributes inside class methods. It’s how each object keeps its own data.