一、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中字符串与数字相互转换的方法。包括使用string模块的atoi/atof函数将字符串转换为整数或浮点数,以及使用int()函数进行转换。同时也介绍了如何使用字符串格式化方法将数字转换为字符串。
一、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转换成的字符串

被折叠的 条评论
为什么被折叠?