How to get python to return floating point?

I want python to return 0.5 if I write 1/2 (and not 1.0 / 2.0). how to get python to return floating point? (I tried using getcontext (). The decimal form form module)

thank

Ariel

+3
source share
3 answers

Use this or switch to Python 3.0+

from __future__ import division
+8
source
from __future__ import division
+4
source

Python 3.x .

Python 2.2 from __future__ import division, / . //, - .

. PEP238 - .

+3

Source: https://habr.com/ru/post/1734549/


All Articles