Thanks to theidioms.com

Learn Python for Data Science (Course I)

Learn Python for Data Science (Course I)

Standard Libraries in Python

This chapter gives you a basic overview of the different standard libraries in Python.

The Python Standard Library is a collection of script modules accessible to a Python programmer to simplify the programming process and eliminating the need to rewrite commonly used commands. They can be used by ‘calling/importing’ them at the beginning of a script. Generally, these standard libraries are installed alongside Python as packages by Python installers.

Below are some of the standard libraries that are generally used in Python. Familiarity with these libraries is extremely helpful in repetitive tasks and commonly occurring problems.

  • os module provides dozens of functions for interacting with the operating system.
  • shutil module provides a higher-level interface on files and collections of files that is easier to use.
  • glob module provides a function for making file lists from directory wildcard searches.
  • argparse module provides a more sophisticated mechanism to process command-line arguments.
  • re module provides regular expression tools for advanced string processing. For complex matching and manipulation, regular expressions offer succinct, optimized solutions.
  • math module gives access to the underlying C library functions for floating-point math.
  • random module provides tools for making random selections.
  • statistics module calculates basic statistical properties (the mean, median, variance, etc.) of numeric data.
  • datetime module supplies classes for manipulating dates and times in both simple and complex ways.
  • zlib, gzip, bz2, lzma, zipfile and tarfile modules support common data archiving and compression formats
  • timeit module adds a modest performance advantage.
  • doctest module provides a tool for scanning a module and validating tests embedded in a docstrings of a program.
  • unittest module is not as effortless as the doctest module, but it allows a more comprehensive set of tests to be maintained in a separate file.
  • reprlib module provides a version of repr() customized for abbreviated displays of large or deeply nested containers.
  • pprint module offers more sophisticated control over printing both built-in and user-defined objects in a way that is readable by the interpreter.
  • textwrap module formats paragraphs of text to fit a given screen width.
  • threading module can run tasks in the background while the main program continues to run.
  • decimal module offers a Decimal datatype for decimal floating-point arithmetic.

The libraries listed above are some of the widely used standard libraries in Python. You can always refer to the official documentation to get a list of all the standard libraries in Python for different tasks.

In the upcoming chapter, Virtual Environments and Packages in Python, we will discuss how you can set up a proper programming environment for importing and using libraries that are not a part of the Standard Libraries in python.

Leave your thought here

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami