What is OOP?
- OOP stands for Object-Oriented Programming.
- It is a programming approach where we organize programs using classes and objects.
Why Do We Use OOP?
- Organize code
- Reuse code
- Reduce code duplication
- Maintain large programs easily
- Represent real-world entities
- Improve code structure
What is a Class?
- A class is a blueprint or template used to create objects.
class Student:
pass
- Student → Class
What is an Object?
- An object is an instance of a class.
class Student:
pass
student1 = Student()
- Student → Class
- student1 → Object
Class vs Object
Class Object
Blueprint Real instance
Defines structure Uses that structure
Logical entity Physical/runtime entity
Example: Student Example: student1
Creating a Class
- We use the class keyword.
class Student:
name = "Punitha"
age = 22
- Student → Class
- name → Attribute
- age → Attribute
Creating an Object
- We create an object by calling the class.
class Student:
name = "Punitha"
age = 22
student1 = Student()
print(student1.name)
print(student1.age)
Output:
Punitha
22
Top comments (0)