Interview Q&A / Python

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between absolute and relative imports in Python?

SHORT ANSWER

An absolute import gives the full path from the project root, like from shop.billing import total. A relative import uses dots to start from the current package, like from .billing import total. Relative imports work only inside packages.

Explain it simply

Absolute is giving a full postal address: "Flat 4, Gandhi Road, Pune". Relative is saying "the house next door" or "one street up", which only makes sense if you know where you are standing now. One dot means this package, two dots mean the parent package.

Example

text
shop/
    __init__.py
    billing.py
    utils/
        __init__.py
        money.py
python
# inside shop/billing.py
from shop.utils.money import rupees     # absolute
from .utils.money import rupees         # relative, same package
from . import utils                     # the sibling package

# inside shop/utils/money.py
from ..billing import total             # one level up

Running a file inside a package directly, like python shop/billing.py, makes relative imports fail with "attempted relative import with no known parent package". Run it as a module instead: python -m shop.billing.

What to say in the interview

"Absolute imports spell out the full package path and are the recommended default because they are clear and survive file moves. Relative imports use dots and are handy inside a package, but only work when the file is imported as part of that package, not when run as a plain script."

#python#modules#packages

Related questions

Practise more Python questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Python quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.