I want python to return 0.5 if I write 1/2 (and not 1.0/2.0). how do I make python to return the floating point? (I tried using getcontext().prec form decimal module)
thanks
Ariel
使用它,或切换到Python 3.0+
from __future__ import division
from __future__ import division
Python 3.x works the way you want by default.
Python 2.2 and greater support from __future__ import division
, which makes / return floating point. There is also the // operator that still performs integer division when needed.
Also see PEP238 - Changing the Division Operator .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.