Python Number()

Python Number

, Number

Number

var1 = 1
var2 = 10

del Number

del

del var1[,var2[,var3[....,varN]]]]

del

del var
del var_a, var_b

Python

  • (Int) -
  • (long integers) - L
  • (floating point real values) - 2.5e2 = 2.5 x 102 = 250
  • (complex numbers) - a + bj,complex(a,b) ab
intlongfloatcomplex
1051924361L0.03.14j
100-0x19323L15.2045.j
-7860122L-21.99.322e-36j
0800xDEFABCECBDAECBFBAEl32.3+e18.876j
-0490535633629843L-90.-.6545+0J
-0x260-052318172735L-32.54e1003e+26J
0x69-4721885298529L70.2-E124.53e-7j
  • "L""L""1"Python"L"
  • Pythona + bj,complex(a,b) ab


Python Number

int(x [,base ])         x  
long(x [,base ])        x  
float(x )               x  
complex(real [,imag ])    
str(x )                  x   
repr(x )                 x   
eval(str )              Python,  
tuple(s )                s   
list(s )                 s   
chr(x )                   
unichr(x )              Unicode  
ord(x )                   
hex(x )                   
oct(x )                   

Python math cmath

Python math cmath

Python math

Python cmath

cmath math cmath math

math cmath

import math

math :

>>> import math
>>> dir(math)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>>

cmath

>>> import cmath
>>> dir(cmath)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cos', 'cosh', 'e', 'exp', 'inf', 'infj', 'isclose', 'isfinite', 'isinf', 'isnan', 'log', 'log10', 'nan', 'nanj', 'phase', 'pi', 'polar', 'rect', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau']
>>>

>>> import cmath
>>> cmath.sqrt(-1)
1j
>>> cmath.sqrt(9)
(3+0j)
>>> cmath.sin(1)
(0.8414709848078965+0j)
>>> cmath.log10(100)
(2+0j)
>>>

Python

( )
abs(x)abs(-10) 10
ceil(x) math.ceil(4.1) 5
cmp(x, y) x < y -1, x == y 0, x > y 1
exp(x) ex(ex),math.exp(1) 2.718281828459045
fabs(x)math.fabs(-10) 10.0
floor(x) math.floor(4.9) 4
log(x) math.log(math.e)1.0,math.log(100,10)2.0
log10(x) 10xmath.log10(100) 2.0
max(x1, x2,...)
min(x1, x2,...)
modf(x) xx
pow(x, y) x**y
round(x [,n])xn
sqrt(x) x


Python

Python

choice(seq)random.choice(range(10))09
randrange ([start,] stop [,step]) 1
random() [0,1)
seed([x]) seedseedPythonseed
shuffle(lst)
uniform(x, y)[x,y]


Python

Python

acos(x)x
asin(x)x
atan(x)x
atan2(y, x) X Y
cos(x)x
hypot(x, y) sqrt(x*x + y*y)
sin(x)x
tan(x)x
degrees(x),degrees(math.pi/2) 90.0
radians(x)


Python

pi pi
e ee