Python 基础-数值

来源:互联网 发布:unity3d导航网格寻路 编辑:程序博客网 时间:2024/06/06 01:05
>>> a = 3.0 + 4.0j
>>> float(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
>>> a.real
3.0
>>> a.imag
4.0
>>> abs(a) # sqrt(a.real**2 + a.imag**2)
5.0



>>> tax = 12.5 /100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _ # 交互模式下,最近一次表达式输出保存在_变量中。
113.0625 # 这意味着把Python当做桌面计算器使用时,它可以更容易的进行连续计算
>>> round(_,2)
113.06
>>>


原创粉丝点击