标签:index border 小数点 包括 bsp html base cin pac
本节内容如下:
整数包括:正数和负数和零。查看原文
显示方式:十进制(默认)、二进制(0b)、八进制(0o)、十六进制(0x) 转换函数:bin(I) / oct(I) / hex(I) / int(str,base)
a = 100print(bin(a)) # 0b1100100print(oct(a)) # 0o144print(hex(a)) # 0x64 |
带小数点的数字,可以使用科学计数法3.14e-10,例如 :
x = 314print(‘%e‘ %x) # 3.140000e+02 |
复数包括实部和虚部,例如:
c = 3+4jprint(c.real) # 3.0print(c.imag) # 4.0c = complex(3,4)print(c) # (3+4j) |
使用分数需要使用Python中的Fraction模块,需要导入包:
from fractions import Fractionf1 = Fraction(3,4)print(f1) # 3/4f2 = Fraction(5,16)print(f1+f2) # 17/16print(f1*f2) # 15/64 |
标签:index border 小数点 包括 bsp html base cin pac
原文地址:http://www.cnblogs.com/2xkt/p/7634812.html