python-3.3

Division in Python 2.7. and 3.3 [duplicate]

好久不见. 提交于 2019-11-25 23:18:47
问题 This question already has answers here : Python division (12 answers) Closed 5 years ago . How can I divide two numbers in Python 2.7 and get the result with decimals? I don\'t get it why there is difference: in Python 3: >>> 20/15 1.3333333333333333 in Python 2: >>> 20/15 1 Isn\'t this a modulo actually? 回答1: In python 2.7, the / operator is integer division if inputs are integers. If you want float division (which is something I always prefer), just use this special import: from __future__