Using Libraries

Learn what libraries are in Python, and how we can create a custom library and import it into another piece of code.

A library in Python is essentially a collection of modules, which are files containing Python code. Libraries save time and effort by letting programmers use pre-built functions. An added benefit is that as more and more people use a library, code gets tested, due to which bugs can be fixed and code can be optimized.

Python has a vibrant ecosystem of libraries covering diverse domains. While a detailed discussion on Python's ecosystem is beyond the scope of this course, some of the popular libraries are listed below to give a taste of what you can expect in your exciting Python journey.

  • Data science: NumPy, pandas

  • Data visualization: Matplotlib, Seaborn, Plotly

  • Machine learning and image processing: scikit-learn, TensorFlow, PyTorch, Keras, OpenCV

  • Natural language processing: Natural Language Toolkit, spaCy

  • Web development: Django, Flask

  • Scientific computing: SciPy

  • Web scraping: Scrapy

In this lesson, we will create a library named educative_math_library that can perform basic math operations like add, subtract, divide, and multiply. To create a library, you must create a module and package it.

Creating a module

Let's start by creating a simple module. Create a file named educative_math_library.py and add the functionality of add, subtract, divide, and multiply functions.

Get hands-on with 1200+ tech skills courses.