ITPub博客

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

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

IT生活 作者:jmctian 时间:2021-09-11 10:19:13 0 删除 编辑

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-13

  • 博文量
    0
  • 访问量
    429