Objects in Python
What is an Object?
In real life, everything around us is an object — like a phone, a car, a ball, or a book.
Each object has:
- Properties (like color, size, weight)
- Actions (like ringing, driving, bouncing, or opening)
In Python, it's the same!
An object is something that stores data (like properties) and can do things (like actions).
Python is Object-Oriented
Python is called an Object-Oriented Programming (OOP) language.
This means Python works with objects in a smart way — we can create, use, and manage them easily.
Example of an Object
Let's take a simple example:
x = 5
Here, x is a variable, and it stores the value 5.
But actually, Python treats 5 as an object of type int (which stands for integer).
So:
5is an object- It has properties and actions
You can try:
print(type(x))
This will show:
<class 'int'>
This means x is an object of the class int.
Real-Life Analogy
Let's imagine a dog:
- Its properties: name = "Bruno", color = "brown", age = 3
- Its actions: bark
Key Takeaways
- Everything in Python is an object
- Objects have properties (data) and actions (methods)
- Python is fundamentally object-oriented
- Even simple variables reference objects with types
No comments:
Post a Comment