Python Practice › OOP Programs › Program 27

Person class

EasyOOP Programs · 27 of 48

Create a Person class with name and age and a method to print them.

Advertisement
Output
Name: Asha, Age: 29

Approach

  1. Store the attributes and print them in a method.

Solution

Python
class Person:    def __init__(self, name, age):        self.name = name        self.age = age     def show(self):        print(f"Name: {self.name}, Age: {self.age}") Person("Asha", 29).show()
Output
Name: Asha, Age: 29

Learn the concept

New to this topic? Read the lesson, then come back.

More oop programs

← All 48 OOP Programs

Leave a Comment