1、python数据类型
- numerics, sequences, mappings, classes, instances, exceptions
- Numeric Types: int (包含boolean), float, complex
- int: unlimited length; float: 实现用double in C, 可用 sys.float_info查看
complex: real(实部) & imaginary(虚部),用z.real 和 z.imag来取两部分
具体运算以及法则参见:
https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex
2、例子
import sys
a = 3
b = 4
c = 5.66
d = 8.0
e = complex(c,d)
f = complex(float(a),float(b))
# f = complex(a,b)
print("a is type: ",type(a))
print("c is type: ",type(c))
print("e is type: ",type(e))
print(a+b)
print(d/c)
print(b/a)
print(b//a)
print(e)
print(e+f)
print ("e's real part is: " , e.real)
print ("e's imaginary part is: " , e.imag)
print(sys.float_info)
运行结果:
a is type: <class 'int'>
c is type: <class 'float'>
e is type: <class 'complex'>
7
1.4134275618374559
1.3333333333333333
1
(5.66+8j)
(8.66+12j)
e's real part is: 5.66
e's imaginary part is: 8.0
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)