Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'algorithm': 0.04; 'explicitly': 0.05; 'true,': 0.05; 'subject:Python': 0.06; 'context': 0.07; 'float': 0.07; 'indexing': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; "they've": 0.09; 'jan': 0.12; 'contract.': 0.16; 'division.': 0.16; 'integers,': 0.16; 'operands.': 0.16; 'operates': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'similarly,': 0.16; 'violated': 0.16; 'wrote:': 0.18; 'dependent': 0.19; 'value.': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'passes': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'division': 0.31; 'int,': 0.31; 'requesting': 0.31; 'used,': 0.33; 'case,': 0.35; 'operations': 0.35; 'but': 0.35; 'there': 0.35; 'possible': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'two': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'contract': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'most': 0.60; 'matter': 0.61; 'received:173': 0.61; "you're": 0.61; 'name': 0.63; 'skip:n 10': 0.64; 'talking': 0.65; 'expectations': 0.74; 'received:fios.verizon.net': 0.84; 'standing': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Why Python 3? Date: Sun, 20 Apr 2014 20:09:25 -0400 References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398039008 news.xs4all.nl 2836 [2001:888:2000:d::a6]:53715 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70445 On 4/20/2014 7:13 PM, Gregory Ewing wrote: > 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 The name 'floor division' and the float result are intentional, not accidents. > 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. Not necessarily if the float has an integer value. The intention of the change was to make the value of number operations less dependent on the type of the operands. Where the result type does matter is if the result is used, for example, in indexing -- Terry Jan Reedy