5.2. The math moduleΒΆ

The math module contains the kinds of mathematical functions you would typically find on your calculator. As we noted above, when we import math, we create a reference to a module object that contains these elements.

Here are some items from the math module in action.

Mathematical functions do not need to be constructed. They simply perform a task. They are all housed together in a module called math. Once we have imported the math module, anything defined there can be used in our program. Notice that we always use the name of the module followed by a dot followed by the specific item from the module (math.sqrt). You can think of this as lastname.firstname where the lastname is the module family and the firstname is the individual entry in the module.

Check your understanding

    modules-3-1: Which statement allows you to use the math module in your program?

  • import math
  • The module must be imported before you can use anything declared inside the module.
  • include math
  • The correct term is not include, but you are close.
  • use math
  • You will be using parts of the module, but that is not the right term.
  • You don't need a statement. You can always use the math module
  • You cannot use a Python module without a statement at the top of your program that explicitly tells Python you want to use the module.
You have attempted of activities on this page
5.1. Modules"> 5.3. The random module">Next Section - 5.3. The random module