Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Why Python 3? Date: Mon, 21 Apr 2014 11:13:23 +1200 Lines: 33 Message-ID: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 5KHKjfxdLuLbZv6EQEyc7gBDjEtfsy5+F7ZnMWD3i6OkpNg/yO Cancel-Lock: sha1:js3MncbHySyR6eokMbSiawI3XAw= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:70438 Terry Reedy wrote: > On 4/19/2014 9:06 PM, Gregory Ewing wrote: > >> Similarly, when you write // you're explicitly requesting >> integer division. > > One is requesting 'floor division' > > >>> 3.0//2.0 > 1.0 In general that's true, but I'm talking about a context in which you have some expectations as to the types of the operands. Most of the time, there are two possible scenarios: 1) The algorithm operates on integers, and the contract is that you only get passed ints. In that case, you use // and know that the result will be an int. 2) The algorithm operates on non-integers, and the contract is that you get passed either ints or floats, with ints being understood as standing in for floats. In that case, you use / and know that it will perform float division and return a float. If someone passes you a float in case (1) it's true that // won't return an int, but then they've violated the contract. -- Greg