python 字符串与整型转换

来源:互联网 发布:linux常用命令举例 编辑:程序博客网 时间:2024/06/03 20:56
python 数字和字符串转换问题
来自http://www.cnblogs.com/zmlctt/p/4234257.html

一、python中字符串转换成数字

(1)import string 

tt='555'

ts=string.atoi(tt)

ts即为tt转换成的数字

转换为浮点数 string.atof(tt)

(2)直接int

int(tt)即可。

二、数字转换成字符串

tt=322

tem='%d' %tt

tem即为tt转换成的字符串