Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Define Multiple Python Classes in a Single File



Python is not class-based exclusively - the basic unit of code decomposition in Python is the module. A module is a distinct thing that may have one or two dozen closely-related classes. Modules may as well contain functions along with classes. In Python there is rule of  one module=one file.

In Python if you restrict yourself to one class per file (which in Python is not prohibited) you may end up with large number of small files - not easy to keep track.

So depending on the scenario and convenience one can have one or more classes per file in Python.

Updated on: 2023-09-09T23:21:58+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements