Interview Q&A / Python
Python interview questions
Lists, dictionaries, generators, decorators and the Python questions asked in service-company and data roles.
Prefer rapid revision? Practise Python short interview answers →
- What is a circular import in Python, and how do you fix it?
A circular import happens when module A imports B while B imports A, so one of them is used before it is fully loaded, causing ImportError or AttributeError. Fix it by restructuring, moving the shared code to a third module, or importing inside the function.
AdvancedQuick answer1 min read