一、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转换成的字符串 一、python中字符串转换成数字
(方法1)
类中进行导入:import string
str='555'
num=string.atoi(str) num即为str转换成的数字
转换为浮点数:
string.atof(str) (方法2)
直接int
int(str) 二、数字转换成字符串
num=322
str='%d'%num str即为num转换成的字符串
python 数字和字符串转换问题
atoi();atof();%d%tt
