Python Practice › OOP Programs › Program 7
Class and module name
Write a Python program to get an object’s class name and module name.
Output
Product __main__
Approach
type(obj).__name__and__module__.
Solution
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.