from — Easy Examples
Used with import to bring in specific names from a module
Import specific names
Using 'from module import name' for targeted imports.
python
# Import specific functions from math import sqrt, pi, ceil print(sqrt(16)) print(pi) print(ceil(3.2)) # Import and rename from datetime import datetime as dt print(dt.now().year) # from ... import makes names directly available # No need for module prefix from random import randint, choice print(randint(1, 10)) print(choice(["red", "blue", "green"]))
'from X import Y' brings Y directly into your namespace. This avoids repeating the module name but can cause naming conflicts.
Want to try these examples interactively?
Open Easy Playground