python float类型使用方法
2016-01-21 15:25
946 查看
今天我们来看看python 中float 方法
1: 获取值的最简化结果
def
as_integer_ratio(self):
# real signatureunknown; restored from __doc__
"""
float.as_integer_ratio() -> (int,int)
Return a pair of integers, whoseratio is exactly equal to the original
float and with a positivedenominator.
Raise OverflowError on infinities anda ValueError on NaNs.
>>>(10.0).as_integer_ratio() #### 这里给出了使用方法,返回了元组类型
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>>(-.25).as_integer_ratio()
(-1, 4)
"""
2:复数取共轭
3:十六进制转为浮点数
4:将浮点数转换为十六进制
5:判断是不是整数,返回bool 值
测试:
1: 获取值的最简化结果
def
as_integer_ratio(self):
# real signatureunknown; restored from __doc__
"""
float.as_integer_ratio() -> (int,int)
Return a pair of integers, whoseratio is exactly equal to the original
float and with a positivedenominator.
Raise OverflowError on infinities anda ValueError on NaNs.
>>>(10.0).as_integer_ratio() #### 这里给出了使用方法,返回了元组类型
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>>(-.25).as_integer_ratio()
(-1, 4)
"""
2:复数取共轭
a = 1.1 b = 10.5 c = 2 + 1.3J ### 这个例子才能体现出来 print("a",a.conjugate()) print("b",b.conjugate()) print("c",c.conjugate()) a 1.1 b 10.5 c (2-1.3j)
3:十六进制转为浮点数
def fromhex(self, string): # real signature unknown; restored from __doc__ """ float.fromhex(string) -> float Create a floating-point number from a hexadecimal string. >>> float.fromhex('0x1.ffffp10') ### 使用方法 2047.984375 >>> float.fromhex('-0x1p-1074') -5e-324 """ return 0.0
4:将浮点数转换为十六进制
def hex(self): # real signature unknown; restored from __doc__ """ float.hex() -> string Return a hexadecimal representation of a floating-point number. >>> (-0.1).hex() #### 使用方法 '-0x1.999999999999ap-4' >>> 3.14159.hex() '0x1.921f9f01b866ep+1' """ return ""
5:判断是不是整数,返回bool 值
def is_integer(self, *args, **kwargs): # real signature unknown """ Return True if the float is an integer. """ pass
测试:
a = 1.1 b = 10.5 c = 2 + 1.3J d = 5.0 print("a",a.is_integer()) print("b",b.is_integer()) print("d",d.is_integer()) ######## 返回 结果 bool类型 a False b False d True
相关文章推荐
- python新手动手练习!!
- Python脚本email
- Python脚本sendmail
- 用命令访问D:\python学习\wendjia教程\aa.py
- python处理url中的中文编码,以及其他编码问题
- 我写的第一行python
- python之open()函数
- python学习笔记1.22
- 解决python中路径中包含中文无法找到文件的问题
- python:笔记for循环中的else
- python 数字有关的总结
- 在python中获取当前位置所在的行号和函数名
- Python任务调度之sched
- mac install MySQL-python
- 真机上运行Python脚本 A new session could not be created问题解决
- 廖雪峰python学习笔记——函数式编程
- 什么是尾递归(python引例)
- 【Python3】input/print:一行写不下,换多行
- 第一个kaggle项目Digit Recognizer
- Python模块常用的几种安装方式