Python Tutorial

Introduction

Edit Template

Python Tutorial

Introduction

Edit Template

Python OOP

In Python, Object-Oriented Programming (OOP) allows us to structure our code around real-world entities. Instead of just writing functions and variables randomly, we group related data and actions into classes and objects.

What is a Class?

A class is like a blueprint. It defines the structure of something but doesn’t actually hold real data. For example, if you want to describe a “Student”, the class would define what kind of information a student has (like name, age, or marks), but it won’t store any actual student data until you create an object.

You can create a class using the class keyword.

				
					class Student:
    name = "Areeba"
    age = 19

				
			

This class doesn’t do anything yet — it just defines two properties: name and age.

What is an Object?

An object is a real copy of the class — it holds real data. You create an object by calling the class like a function.

				
					person = Student()
print(person.name)
print(person.age)


				
			
A Complete Example

Here’s how it all works together:

				
					class Student:
    name = "Areeba"
    age = 19

learner = Student()
print(learner.name)
print(learner.age)

				
			

Output:

				
					Areeba
19

				
			

Here, Student is our class, and learner is an object created from it. We access the values inside the object using dot notation, like learner.name.

Summary

A class defines what an object should have, while an object is an actual example of that class. Think of a class as a recipe, and the object as the dish made from it.

Scroll to Top