from

KeywordPython 2.0+Beginner

Used with import to bring in specific names from a module

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

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.

Try in Playground

Tags

languagesyntaxcoreimportmodule

Related Items