1. Basic
var = 1 #int (signed integers)var = 1L #long (long integers )var = 1.1 #floating-pointvar = 3+3j #complex (complex numbers)
2. convert
var = 1int(var)long(var)float(var)complex(var) #real part is var, imaginary part is 0complex(x, y) #real part is x, imaginary part is y
3. Mathematical function
import mathvar = 1abs(var) #the absolute value of varceil(var)floor(var)cmp(x, y) #If xy, return 1.exp(var) #e^varfabs(float(var))log(var)log10(var)max(x1, x2, ...)min(x1, x2, ...)modf(var) #This method returns the fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float.pow(x, y) #x^yround(x [,n]) #x rounded to n digits from the decimal point.sqrt(x)
4. Random number function
import randomrandom.choice(seq) #returns a random item from a list, tuple, or stringrandom.randrange([start,] stop [,step]) #returns a randomly selected element from range(start, stop, step).#start -- Start point of the range. This would be included in the range.#stop -- Stop point of the range. This would be excluded from the range.#step -- Steps to be added in a number to decide a random number.random.random() #A random float r, such that 0 <= r <=1random.seed([x]) #The method seed() sets the integer starting value used in generating random numbers. Call this function before calling any other random module function.#x -- his is the seed for the next random number. If omitted, then it takes system time to generate next random number.random.shuffle(lst) #Randomizes the items of a list in place. Returns None.random.uniform(x ,y) #A random float r, such that x<=r<=y.
5. Trigonometric functions
import mathacos(x)asin(x)atan(x)atan2(y,x) #atan(y/x)cos(x)sin(x)tan(x)hypot(x, y) #Return the Euclidean norm, sqrt(x*x + y*y).degrees(x) #Converts angle x from radians to degrees.radians(x) #Converts angle x from degrees to radians.pie