python - Python 中的 float

标签 python floating-point

我正在通过 Learn Python The Hard Way 学习,我遇到了:

Notice the math seems “wrong”? There are no fractions, only whole numbers. Find out why by researching what a “floating point” number is.

我已经阅读了它的内容:http://docs.python.org/tutorial/floatingpoint.html

我不知道如何输出 float ,我考虑过使用 round(3 + 3, 2)

这样对吗?

最佳答案

对于 float ,您可以在数字后写一个句点和一个零(如果它是整数)。

像这样:

1.0 <---- float 。

1 <-------- 整数

这就是 python 解释它们的方式。

if my_answer != your_question:
    print "I did not understand your question. Please rephrase it."
else:
    print "Good luck. Python is fun."

我同意 rohit,不需要 0。虽然它使初学者更容易。

关于python - Python 中的 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4432481/

相关文章:

整数对象上的Python调用方法

java - 如何在 Python 中记录返回的列表

python - Snakemake:MissingInputException - 缺少所有规则的输入文件

floating-point - 并行性: Subtly different floating point results?

algorithm - 位与int/float随机数生成器的关系

python - 无法导入 form_for_model

python - 停止 Python 函数覆盖输入

python - 如何将字符串列表更改为 float 列表

c - 查找不能表示为 IEEE-754 32 位 float 的最小整数

c++ - 为什么 `precise`限定符不生效?