Python怎么把字符串变成数字格式

图片[1]-Python怎么把字符串变成数字格式-uusu优素-乐高,模型,3d打印,编程

Python怎么把字符串变成数字格式

方法一:

类中进行导入string

importstring
str='555'
num=string.atoi(str)

num即为str转换成的数字

转换为浮点数:

string.atof(str)

方法二:

直接使用int

int(str)

补充:数字转换成字符串

num=322
str='%d'%num

str即为num转换成的字符串

原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享