Chapter XV ------------ mathematical basis python module: math

Mathematics module: math

This module built-in functions to compare previous learning

Import package: Import Math

Returns the integer function   (ceil, floor built-in function in comparison round):

ceil (): rounding up (as long as the decimal point, up to nearly 1)  

import math
res=math.ceil(6.5)
print(res)

floor (): rounded down (figures below the decimal point are deleted)

import math
res=math.floor(6.999)
print(res)

Function that returns a floating-point type:

pow (): calculates a number N of power

print(math.pow(2,3))

sqrt (must put a positive number): square root

print(math.sqrt(9))

modf (): The composition and decimal numbers separated by a positive tuple

Return Value :( fractional part, the integer part)

Math Import 
RES = math.modf (. 6)
Print (RES)
outputs: (0.0,6.0)

copysign (): the first number is determined by the sign of the sign behind a number of

Math Import 
RES = math.copysign (. 3, -4)
Print (RES)
outputs: -3.0

fsum (): the data container summing operation (the container can not be str)

import math
str1=[1,2,3,4,5]
res=math.fsum(str1)
print(res)
Constant (not a function): pi e
pi PI
Import Math
Print (Math.PI)

Import Math
Print (Math.E)
 
 

 



 

 

 

Guess you like

Origin www.cnblogs.com/szc-boke/p/11263282.html