在python中,将字符串转换为整形有两种方法:1、使用string库中的atoi函数将字符串转换为数字;2、使用int内置函数将字符串直接转换为数字类型。
(1)import string
tt='555'
ts=string.atoi(tt)
tts是tt转换成的数字
转换为浮点数 string.atof(tt)
(2)直接int
int(tt)即可。
推荐课程:Python入门及高级教学视频(极客学院)
在python中,将字符串转换为整形有两种方法:1、使用string库中的atoi函数将字符串转换为数字;2、使用int内置函数将字符串直接转换为数字类型。
(1)import string
tt='555'
ts=string.atoi(tt)
tts是tt转换成的数字
转换为浮点数 string.atof(tt)
(2)直接int
int(tt)即可。
推荐课程:Python入门及高级教学视频(极客学院)