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
| int | long | float | complex |
|---|---|---|---|
| 10 | 51924361L | 0.0 | 3.14j |
| 100 | -0x19323L | 15.20 | 45.j |
| -786 | 0122L | -21.9 | 9.322e-36j |
| 080 | 0xDEFABCECBDAECBFBAEl | 32.3+e18 | .876j |
| -0490 | 535633629843L | -90. | -.6545+0J |
| -0x260 | -052318172735L | -32.54e100 | 3e+26J |
| 0x69 | -4721885298529L | 70.2-E12 | 4.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 |
www***[email protected]
range()
range() 0
www***[email protected]
913***[email protected]
cmp(x, y) python3.x
913***[email protected]
clearlove
102***[email protected]
Python ASCII a+1 int('a') , == --- == ord('a') chr(59)
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> ord('b') # convert char to int 98 >>> chr(100) # convert int to char 'd' >>> unichr(100) # return a unicode byte u'd' >>>clearlove
102***[email protected]
xjsnight
267***[email protected]
abs() fabs()
abs(-10) 10math.fabs(-10) 10.0
xjsnight
267***[email protected]
ygl611
ygl***@163.com
Python
1 %2
2 python bin bin(12345) '0b11000000111001', 0b:
>>> bin(12345).replace('0b','') '11000000111001'3 format
>>> "{0:b}".format(12345) '11000000111001' >>>ygl611
ygl***@163.com