Imports & Standard Library
Python's Standard Library is a collection of built-in modules with ready-made functions, classes, and constants.
By importing them, you can use tools for math, random numbers, files, dates, and more β saving time and effort without extra installations.
Importing a Module
Use the import keyword to bring in a module, e.g. import math.
Then access its functions or constants with dot notation: math.sqrt(25), math.pi.
Modules work like toolboxes β import one to use all its tools.
Importing Specific Items
Use from ... import ... to bring in only what you need from a module.
For example: from math import sqrt lets you call sqrt(25) directly.
This keeps code shorter and cleaner, especially if you use the same function often.
Aliasing
You can rename a module when importing it with as.
Example: import random as rnd lets you call rnd.randint(1, 10) instead of random.randint(1, 10).
Aliasing shortens code and avoids name conflicts.
It's also common in conventions, like import numpy as np.
Useful Standard Modules
Here are some commonly used modules from the standard library with documentation links:
mathβ for square roots, constants, and trigonometry;randomβ for generating random numbers, shuffling, and choices;datetimeβ for working with dates, times, and timestamps;osβ for managing files and directories on the operating system;sysβ for interacting with the Python interpreter and command-line arguments;statisticsβ for calculating mean, median, and other statistical values.
Summary
- Python has many built-in modules, ready to import with
import; - You can import a full module or just a specific function;
- Use
asto assign a shorter alias for convenience; - The standard library gives you access to tools for math, randomness, dates, files, and more.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
What are some examples of standard modules I can use in Python?
Can you explain the difference between importing a whole module and importing a specific function?
How do I use aliasing when importing modules?
Awesome!
Completion rate improved to 5
Imports & Standard Library
Swipe to show menu
Python's Standard Library is a collection of built-in modules with ready-made functions, classes, and constants.
By importing them, you can use tools for math, random numbers, files, dates, and more β saving time and effort without extra installations.
Importing a Module
Use the import keyword to bring in a module, e.g. import math.
Then access its functions or constants with dot notation: math.sqrt(25), math.pi.
Modules work like toolboxes β import one to use all its tools.
Importing Specific Items
Use from ... import ... to bring in only what you need from a module.
For example: from math import sqrt lets you call sqrt(25) directly.
This keeps code shorter and cleaner, especially if you use the same function often.
Aliasing
You can rename a module when importing it with as.
Example: import random as rnd lets you call rnd.randint(1, 10) instead of random.randint(1, 10).
Aliasing shortens code and avoids name conflicts.
It's also common in conventions, like import numpy as np.
Useful Standard Modules
Here are some commonly used modules from the standard library with documentation links:
mathβ for square roots, constants, and trigonometry;randomβ for generating random numbers, shuffling, and choices;datetimeβ for working with dates, times, and timestamps;osβ for managing files and directories on the operating system;sysβ for interacting with the Python interpreter and command-line arguments;statisticsβ for calculating mean, median, and other statistical values.
Summary
- Python has many built-in modules, ready to import with
import; - You can import a full module or just a specific function;
- Use
asto assign a shorter alias for convenience; - The standard library gives you access to tools for math, randomness, dates, files, and more.
Thanks for your feedback!