美文网首页
python 数据类型转换

python 数据类型转换

作者: 最可爱的年年年年 | 来源:发表于2018-10-28 10:28 被阅读0次

强制类型转换

int 函数

  1. 把符合数学格式的数字型字符串转换成整数
  2. 把浮点数转换成整数,但是只是简单的取整,而非四舍五入。

float函数

将整数和字符串转换为浮点数

str 函数

将数字转换为字符

list 和 tuple

tuple转list list(tup)
list转tuple tuple(list)

String转list

简单转换 list函数

list(str)
将字符串中的每一个字母作为列表中的一个元素,空格也算一个元素

hi = "hi world"
list(hi)
['h','i',' ','w','o','r,','l','d']
指定分隔符

split

s = "hello,world"
slist = s.split(",")
//['hello','world']

相关文章

网友评论

      本文标题:python 数据类型转换

      本文链接:https://www.haomeiwen.com/subject/egkptqtx.html