2019-07-09
阅读量:
677
如何将数据转为整数或浮点数
1. int(a,base):该函数将任何数据类型转换为整数。如果数据类型是字符串,则“Base”指定字符串所在的基数。
2. float():此函数用于将任何数据类型转换为浮点数
# Python code to demonstrate Type conversion
# using int(), float()
# initializing string
s = "10010"
# printing string converting to int base 2
c = int(s,2)
print ("After converting to integer base 2 : ", end="")
print (c)
# printing string converting to float
e = float(s)
print ("After converting to float : ", end="")
print (e)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论