python

当前位置:中华考试网 >> python >> python编程基础 >> 文章内容

python如何将字符串类型转换为整型?

来源:中华考试网  [2020年10月14日]  【

   在python中,将字符串转换为整型的两种方法是:1、利用string库中的atoi函数将字符串转换成数字;2、直接使用int内置函数将字符串转换成数字类型。

  (1)import string 

  tt='555'

  ts=string.atoi(tt)

  ts即为tt转换成的数字

  转换为浮点数 string.atof(tt)

  (2)直接int

  int(tt)即可。

责编:hym
  • 会计考试
  • 建筑工程
  • 职业资格
  • 医药考试
  • 外语考试
  • 学历考试