Module 5: Introduction to Object-Oriented Programming (OOP)
Creating Classes: `class`, `__init__`, and `self`
-
class
keyword: Used to define a new class.class Dog: pass # pass means 'do nothing', a placeholder
-
__init__
method (Constructor): A special method that is automatically called when you create a new object (instance) of a class. It's used to initialize the object's attributes. The name__init__
has double underscores before and after. -
self
parameter: The first parameter of any method within a class (including__init__
) is conventionally namedself
. It refers to the instance of the class itself. Throughself
, methods can access the attributes and other methods of the same object.