09 June, 2025

Paython lesson 9

Python Lesson 9 - Object Oriented Programming

Python Lesson 9 - Object Oriented Programming

🌟 Introduction to OOP in Python

OOP (Object Oriented Programming) is a method of structuring a program by bundling related properties and behaviors into individual objects.

📘 Python Class Example



class Student:

    def __init__(self, name, grade):

        self.name = name

        self.grade = grade

    def display(self):

        print(f"Student Name: {self.name}")

        print(f"Grade: {self.grade}")

# Creating object

student1 = Student("Rahul", "A")

student1.display()

    

🧠 Key Concepts

  • Class - Blueprint for creating objects
  • Object - Instance of a class
  • Constructor - __init__ method used for initialization
  • Methods - Functions defined in class

📌 Output



Student Name: Rahul

Grade: A

    

No comments:

Post a Comment

thank to you