What a module contains
How do you find out what's in a module? There are two ways: read its documentation, or ask Python itself.
The documentation
Every module of the standard library has a page in Python's official documentation. The list of all of them, grouped by theme, is at docs.python.org/3/library, and the math module's page is docs.python.org/3/library/math.html. Each function has a short description, and often an example. Looking things up there is part of every programmer's day, so it's worth getting used to it early.
dir
In part 4 you used dir("") to list the methods of strings. Given a module, dir lists the names the module contains. The list for math is long, so this session looks at its end, and checks for one name:
>>> import math
>>> names = dir(math)
>>> names[-7:]
['sqrt', 'sumprod', 'tan', 'tanh', 'tau', 'trunc', 'ulp']
>>> "floor" in names
TrueThe list is in alphabetical order. It starts with names wrapped in double underscores, such as __name__, which Python uses for its own bookkeeping; you can skip those. dir shows only the names, so it's a quick reminder of how something was spelled. The documentation tells what each one does.
Modules hold values too
Not everything in a module is a function. The string module holds handy strings of characters:
import string
print(string.ascii_lowercase)
print(string.ascii_uppercase)
print(string.digits)
print(string.punctuation)
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~(string.ascii_letters has both the small and the capital letters.) These save typing, and typos: a hand-typed alphabet with one letter missing is a bug that hides well. Together with in they make it easy to sort characters into groups:
import string
code = "AB-12"
digits = 0
for character in code:
if character in string.digits:
digits += 1
print("Digits:", digits)
Digits: 2Note the difference between the module string and the type of text values, str: they're two different things with similar names.