Python Practice › OOP Programs › Program 27
Person class
Create a Person class with name and age and a method to print them.
Output
Name: Asha, Age: 29
Approach
- Store the attributes and print them in a method.
Solution
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.