Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99206

Re: *= operator

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From BartC <bc@freeuk.com>
Newsgroups comp.lang.python
Subject Re: *= operator
Date Sat, 21 Nov 2015 13:37:25 +0000
Organization A noiseless patient Spider
Lines 34
Message-ID <n2prun$3du$1@dont-email.me> (permalink)
References <a76b1b5b-4321-41bb-aeca-0dac787752d9@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sat, 21 Nov 2015 13:35:20 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="cf45b3961a050227b1103bebc3cbc15a"; logging-data="3518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196OnAcAdW1yw+Bj9I2XoiM"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
In-Reply-To <a76b1b5b-4321-41bb-aeca-0dac787752d9@googlegroups.com>
Cancel-Lock sha1:waXQaZ1FhgrTwLFdqYJo6da4wo0=
Xref csiph.com comp.lang.python:99206

Show key headers only | View raw


On 21/11/2015 13:20, Cai Gengyang wrote:
> This is a piece of code that calculates tax and tip :
>
> def tax(bill):
>      """Adds 8% tax to a restaurant bill."""
>      bill *= 1.08
>      print "With tax: %f" % bill
>      return bill
>
> def tip(bill):
>      """Adds 15% tip to a restaurant bill."""
>      bill *= 1.15
>      print "With tip: %f" % bill
>      return bill
>
> meal_cost = 100
> meal_with_tax = tax(meal_cost)
> meal_with_tip = tip(meal_with_tax)
>
> Does bill *= 1.08 mean bill = bill * 1.15 ?

bill *= 1.08 would mean bill = bill*1.08 (not 1.15; I assume that's a typo).

Although you can never be 100% sure in Python (as * or *= could have 
been redefined to do something else), there's no reason to suspect that 
here.

Also, there's probably some technical difference that someone could up 
with (*= doing in-place modification for example), but that shouldn't 
matter when bill is just a number.

-- 
Bartc

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

*= operator Cai Gengyang <gengyangcai@gmail.com> - 2015-11-21 05:20 -0800
  Re: *= operator BartC <bc@freeuk.com> - 2015-11-21 13:37 +0000
  Re: *= operator Steven D'Aprano <steve@pearwood.info> - 2015-11-22 00:39 +1100
    Re: *= operator Joel Goldstick <joel.goldstick@gmail.com> - 2015-11-21 08:58 -0500
  Re: *= operator "Frank Millman" <frank@chagford.com> - 2015-11-21 15:46 +0200
    Re: *= operator Cai Gengyang <gengyangcai@gmail.com> - 2015-11-21 05:55 -0800

csiph-web