首页 > IT职业 > IT生活 > Python怎么把字符串变成数字格式

Python怎么把字符串变成数字格式
方法一:
类中进行导入string
import string str='555' num=string.atoi(str)
num即为str转换成的数字
转换为浮点数:
string.atof(str)
方法二:
直接使用int
int(str)
补充:数字转换成字符串
num=322 str='%d'%num
str即为num转换成的字符串
更多技术请关注Python视频教程。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2963/viewspace-2834066/ ,如需转载,请注明出处,否则将追究法律责任。