2. Python Standard Library#

The standard library of Python is all the built-in functions of the programming language as well as the modules included with the most common Python distributions. The Python online documentation has an excellent page describing the standard library. These functionalities include built-in functions, constants, and object types, and data types. We recommend that you read these sections in the Python documentation.

In addition, the iframe below contains a PDF of the BYU ACME open-access lab entitled, “The Standard Library”. You can either scroll through the lab on this page using the iframe window, or you can download the PDF for use on your computer. See [BYU ACME, 2023]. Exercise 3.1 below has you work through the problems in this BYU ACME lab. The two Python files used in this lab are stored in the ./code/StandardLibrary/ directory.

2.1. Exercises#

3. A note about answering the exercises#

Just below you will find the first exercises in this training guide. As described in Section Section 1.3, there are a number of ways to interact with Python. You can feel free to use any of these as you work through the exercises we’ve included. But to make things as easy as possible, you can use our answer template. By clicking on the rocket ship shaped button in the menu bar at the top of the page and then select Google Colab and you will be able to open the notebook in Google Colaboratory, where you can execute cells as in any Jupyter Notebook (basic instructions or use of a Notebook) without needed any local python installation. You will only need a Google account to save this notebook to your Drive.

Exercise 3.1

Read the BYU ACME “The Standard Library” lab and complete Problems 1 through 5 in the lab. [BYU ACME, 2023]

Exercise 3.2

Create a python module that prints something (e.g. Hello World!) and run it from the command line using python module_name.py.

Exercise 3.3

Create a Jupyter notebook (.ipynb) with your Python code from Exercise 3.2 and run it in the VS Code text editor.

Exercise 3.4

Write a function that finds the Fibonacci sequence up to an integer N > 0 in the notebook. Now call this function for N = 10 and N=100.

Exercise 3.5

Use the sys module to create a relative path from a Python module, print that path.