from … import

phrase

say it: “FRUM im-PORT” /ˈfrʌm ɪmˈpɔrt/

A Python statement that brings in only the names you want from a module, so you can use them without the module's name in front.

What does from … import do?

from … import brings in just the names you want from a module, so you can use them without the module name in front.

from math import sqrt
print(sqrt(81))  # 9.0

In a sentence

  • “With from … import, the test file uses shipping_cost directly.”
  • “A from … import line brings in sqrt, so you can write sqrt(81).”

Level: Apprentice · More Python terms at this level

Updated