Python - Math module for Number types

Introduction

The following code shows the usage of the built-in math module:

The pow and abs built-in functions, for instance, compute powers and absolute values, respectively.

Demo

import math 
print( math.pi, math.e )                               # Common constants 
print( math.sin(2 * math.pi / 180) )                   # Sine, tangent, cosine 
print( math.sqrt(144), math.sqrt(2) )                  # Square root 
print( pow(2, 4), 2 ** 4, 2.0 ** 4.0 )                 # Exponentiation (power) 
print( abs(-42.0), sum((1, 2, 3, 4)) )                 # Absolute value, summation 
print( min(3, 1, 2, 4), max(3, 1, 2, 4) )              # Minimum, maximum
# w ww .j  av a2s . c o m

Result

The sum function works on a sequence of numbers, and min and max accept either a sequence or individual arguments.

Related Topic