from … import …
`from module import name` brings one specific name out of a module so you can use it directly, without the module prefix.
Used in 129 lessons of the course, from 00.01.
A module is a Python file with useful names: functions, classes, constants. With import math you bring the whole module and write math.sqrt(9). With from math import sqrt you bring only sqrt and write sqrt(9).
Read it left to right: "from this module, import these names". You can bring several separated by commas: from math import sqrt, pi.
It is written this way to keep code shorter and to show clearly which pieces you use. The cost is that the name no longer reminds you where it came from, so pick names that don't clash with your own.
In the course you meet it in the first lesson, in a line like from IPython.display import Markdown, display. Here IPython.display is the module, and Markdown and display are two names ready to use. You will see this pattern in almost every lesson to bring classes and functions from LangChain.
Reach for it when: you use a few pieces of a module many times and want to name them without a prefix.
Examples
Common mistake
from math import sqrt print(math.sqrt(16))
Why: `from math import sqrt` brings only `sqrt`. The name `math` is not defined.
How to write it: Write sqrt(16), or use import math if you want math.sqrt(16).
Common mistake
from math import squareroot
Why: The module exists, but it has no name `squareroot`. Python raises ImportError (cannot import name).
How to write it: Check the exact name in the module's documentation: here it is sqrt.
