Lecture 8 Flashcards
Modules
what is a module and what is its advantage?
A module is just a Python file.
Keep Python files small
Reuse code across multiple files by importing
what is a built in module?
- comes with python by default, we do not need to download them using a package installer.
-We still have to manually import them to use them.
how do you rename a module? (incl. syntax)
- We can give the alias to the module name or give it another name which we can refer it by using an as keyword
- Once renamed, we can’t access the name of the module with old name
syntax:
import modulename as alias
how do you import parts of a module?
from keywrord
from modulename import methods (separated by commas)
how do you import an entire module using from keyword?
from modulename import *
what is an external module?
External modules are downloaded from the internet
You can download external modules using pip
pip - Package management system for Python
how do you use the help keyword?
to get documentation for a module
ex: import termcolor
print(help(termcolor))