`

python函数

 
阅读更多

类型转换函数:

转换整数类型:
>>> int('32')
32
>>> int('hhhh')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'hhhh'
如果将浮点数转换为整数类型则是直接舍去小数点部分

转换为浮点数
>>> float(32)
32.0

转换为字符串
>>> str(32)
'32'

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics