我正在开发一个进行一些浮点计算的程序。 有什么方法可以用 doctests 测试我的功能(提供 float )?
最佳答案
当然,只需根据您对 float 所期望的精度的了解,使用合理的格式来格式化 float ——例如,如果您期望精确到小数点后 2 位数字,则可以使用:
''' Rest of your docstring and then...
>>> '%.2f' % funcreturningfloat()
'123.45'
'''
关于python - 如何用doctest测试 float 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2428618/