2019-03-19
阅读量:
685
python如何将数值转换为整数
Python定义了类型转换函数,以直接将一种数据类型转换为另一种数据类型,这在日常和竞争性编程中非常有用。。
1. int(a,base):该函数将任何数据类型转换为整数。如果数据类型是字符串,则“Base”指定字符串所在的基数。
2. float():此函数用于将任何数据类型转换为浮点数
# 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)
输出:
After converting to integer base 2 : 18
After converting to float : 10010.0






评论(0)


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