Study Notes
Introduction
Classes and objects are fundamental components of object‑oriented programming in
Python. They allow programmers to represent real‑world entities such as students,
employees, or products in the form of software structures.
In large applications, programs often need to manage multiple pieces of related information
together. Classes help group related variables and functions, making the program easier to
design and maintain.
Objects are created from classes and represent individual instances of those classes. By
using objects, developers can build programs that model real systems in an organized and
structured way.
Definition
A class in Python is a blueprint used to create objects. It defines the attributes (data) and
methods (functions) that objects created from the class will have.
An object is an instance of a class. When a class is defined, it describes the structure, but the
actual data is stored in objects created from that class.
For example, a class named Student may define attributes like name and age, while each
student object represents a specific student.
Creating Classes in Python
In Python, classes are defined using the class keyword followed by the class name.
The class definition contains attributes and methods that describe the properties and
behaviors of objects.
For example, a class representing a vehicle may include attributes such as model and speed
along with methods that control movement.
Creating Objects
Objects are created by calling the class name as if it were a function.
When a new object is created, Python allocates memory for that object and initializes its
attributes.