我正在通过 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/