Python Lesson 8: Importing Modules into your Python code

  1. Built In Functions
  2. Get a list of Python Modules installed in your Jupyter Notebook
  3. How to install  modules to your Jupyter notebook
  4. How to import a module into your Jupyter notebook
  5. How to alias a module in Python
  6. How to import only needed items from your imported module

1) Built In Functions

Python includes many built in functions (table below).

Built-in Functions
abs() delattr() hash() memoryview() set()
all() dict() help() min() setattr()
any() dir() hex() next() slice()
ascii() divmod() id() object() sorted()
bin() enumerate() input() oct() staticmethod()
bool() eval() int() open() str()
breakpoint() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()

These functions are always available to use but their functionality is limited. To write more complex programs Python allows you to use Modules. Modules are python programs that extend the functionality of your application. Some modules are part of the Python Standard Library and some are third party libraries. The Jupyter notebook comes with a list of Modules already installed.

2) Get a list of Python Modules installed in your Jupyter Notebook

  1. Open a terminal or command line window
  2. Type the command: conda list and press enter
terminal window
output of conda list command

3) How to install  modules to your Jupyter notebook

  1. Open a terminal or command line window
  2. Use the command conda install
  3. Follow the package instructions

4) How to import a module into your Jupyter notebook

To import a module use the import command

5) How to alias a module in Python

Aliases are used to reduce the amount of code you need to write. They give you a shorthand version of the module name. To use aliases in your import statement use the “as” keyword and then set the alias. .

np is the alias used in this import

6) How to import only needed items from your imported module

To import specific items from your imported module use the from and import keywords:

import specific classes or functions

Recommended Books