后浪云Python教程:Python怎么把字符串变成数字格式

后浪云Python教程: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视频教程。

THE END