ENG 101
Fall 2019
Python Keywords and Math Functions
Keywords (reserved words in Python)
False def if raise None del
import return True elif in try
and else is while as except
lambda with assert finally nonlocal yield
break for not or continue global
pass class from
Note: only False, True, and None are capitalized.
Math Functions
To use math functions: import math. Examples: y = [Link](x) or y= [Link](x*[Link]/2)
Name Arguments Result
acos x Arc cosine of x (result in radians)
acosh x Inverse hyperbolic cosine
asin x Arc sine of x (radians)
asinh x Inverse hyperbolic sine of x
atan x Arc tangent of x (radians)
atan2 x Arc tangent of y/y (radians) taking into consideration of signs
Of both x and y
atanh x Inverse hyperbolic tangent of x
ceil x Smallest integer that is less than or equal to x
copysign x,y Returns a float with absolute value of x but sign of y.
cos x Cosine of x (measured in radians)
cosh x Hyperbolic cosine of x
degrees x Angle for x (measured in randians)
erf x Error function value at x
erfc x Complementary error function at x
exp x Exponential of x
epm1 x Exponential minus 1: exp(x)-1, used for precision when x is
Small
fabs x Absolute value of a float x
factorial x Factorial of x (x integer: otherwise ValueError)
floor x Largest integer that is less than or equal to x
fmod x, y Returns remainder of x when divided by y. May differ from X % y.
Name Arguments Result
Returns mantissa (m) and exponent (int power of 2) for x:
frexp x m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
Return an accurate floating point sum of values in the iterable.
fsum iterable
Assumes IEEE-754 floating point arithmetic.
gamma x Gamma function of x
gcd x,y Returns int greatest common divisor of x, y
hypot x, y Euclidian distance (hypotenuse) of x, y (scalars)
True if “close” according machine precision
Optional parameters for relative tolerance, absolute tolerance values
isclose x, y
NaN is not close to anything, even itself
Inf and –inf are only close to themselves
isfinite x True if neither NaN or –inf or inf
isinf x True if value is either –inf or inf
isnan x True if NaN (not a number or undefined)
idexp x, y Return x * (2**y).
lgamma x Natural logarithm of absolute value of the Gamma function at x
log x [,base] Natural logarithm unless base is provided
log10 x Base 10 logarithm of x
log1p x Natural log of 1+x(base e) highly accurate for x near zero
log2 x Base 2 log of x
modf x Returns the fractional and integer portion of x: both have sign of x
pow x, y Returns x**y (x to the power of y)
radians x Converts angle in degrees to radians
sin x Sine of x (x measured in radians)
sinh x Hyperbolic sine of x
sqrt x Square root of x
tan x Tangent of x (x measured in radians)
tanh x Hyperbolic tangent of x
trunc x Truncate a float to nearest integer (int) (differs from floor)
e 2.718281828459045
pi 3.141592653589793
tau 6.283185307179586 (2 pi)