Overview
The math library is a useful library that allows you to use more complex tools to create python programs that can handle mathematics.Rather than explain this library in detail we are going to cover a few brief methods and then some examples that allow you to get started and if you want a more advanced feature or something that isn't here then this should be covered in the documentation.
Keywords
Number Theorymath.log10(x) - Return the log base 10 of x
math.log(x,[base]) - Returns natural log x, unless an optional base is supplied
math.pow(x,y) - Returns x raised to the power y
math.sqrt(x) - Returns the square root of a number
Angular Conversion
math.degrees(x) - Converts an angle in radians in to degrees
math.radians(x) - Converts an angle in degrees in to radians
Trigonometric Functions
math.cos(x) - Returns the cosine of x, when x is in radians
math.sin(x) - Returns the sine of x, when x is in radians
math.tan(x) - Returns the tangent of x, when x is in radians
math.acos(x) - Returns the inverse cosine of x, when x is in radians
math.asin(x) - Returns the inverse sine of x, when x is in radians
math.atan(x) - Returns the inverse tangent of x, when x is in radians
math.hypot(x,y) - Calculates the vector distance between x to y.
Hyperbolic Fucntions
maths.acosh(x) - As above but hyperbolic
maths.asinh(x)
maths.atanh(x)
maths.cosh(x)
maths.sinh(x)
maths.atanh(x)
Constants
math.pi - Returns the constant Pi
math.e - Returns natural e
Example
A short example of some of the above keywords in action.import math x = math.pi / 2 print (math.sin(x)) x = 90 x = math.radians(x) print (math.sin(x)) x = 144 print (math.sqrt(x))
1.0 1.0 12.0
Related Sections
Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.Tkinter - Learn the key features of the tkinter to allow you to create user interfaces for your python programs.
Related Pages
Pickle - The pickle library allows a program to save data in a binary file.Python - List Comprehension - Create powerful list comprehension expressions.
Python - Generators - Learn about generator statements.
Python - Data types - The learn about the key datatypes in the python language.
Tkinter - Combo Box - This is a short example showing how to use combo boxes in a GUI.
Tkinter - Radio Buttons - A short example of how to create a GUI with radio buttons.
Tkinter - Canvas - Canvas allows for a range of shapes to be plotted, such as circles, squares, lines