Skip to main content

/docs/images/banner.png

Python

OOP concepts

Write python programs to understand different Object-oriented features in Python programs based on Classes, objects and constructors.

class Student:
def __init__(self, name, age, roll_no):
self.name = name
self.age = age
self.roll_no = roll_no

def display(self):
print("Name: ", self.name)
print("Age: ", self.age)
print("Roll No: ", self.roll_no)


print("\nStudent 1:")
s1 = Student("John", 23, 101)
s1.display()
print("\nStudent 1:")
s2 = Student("Jane", 22, 102)
s2.display()