如何在 Python 3 中将整数转换为浮点数

Python的float()方法将整数转换为浮数. 若要使用此函数,请在列表中添加一个整数:

1float(57)

在这种情况下,将57转换为57.0

让我们声明f等于57,然后打印出新的浮动:

1f = 57
2print(float(f))
1[secondary_label Output]
257.0

通过使用 float() 函数,我们将整数转换为 float。

如果您想了解更多关于 Python 中的不同数据类型转换的信息,请参阅我们的教程(https://andsky.com/tech/tutorials/how-to-convert-data-types-in-python-3)。 有关 Python 的更多信息,请参阅我们的教程(https://www.digitalocean.com/community/tutorial_series/how-to-code-in-python-3)系列。

Published At
Categories with 技术
comments powered by Disqus