发布时间:2022-07-01 09:40:53 人气:140 作者:多测师
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怎么把字符串变成数字格式,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/