Python Practice › OOP Programs › Program 7

Class and module name

EasyOOP Programs · 7 of 48

Write a Python program to get an object’s class name and module name.

Advertisement
Output
Product
__main__

Approach

  1. type(obj).__name__ and __module__.

Solution

Python
class Product:    pass p = Product()print(type(p).__name__)print(Product.__module__)
Output
Product
__main__

Line by line

Line 6

The module is __main__ because the class is defined in the script being run.

Learn the concept

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

More oop programs

← All 48 OOP Programs

Leave a Comment