热线电话:13121318867

登录
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.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子