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


Groups > comp.lang.python > #78601

Re: Assignment Operators?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!lightspeed.eweka.nl!lightspeed.eweka.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.054
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'operator,': 0.09; 'cc:addr :python-list': 0.11; 'bitwise': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'or.': 0.16; 'zero.': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'appears': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'errors': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; '>>>>': 0.31; 'url:wikipedia': 0.31; 'there,': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'false': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'pm,': 0.38; 'read': 0.60; 'numbers': 0.61; 'more': 0.64; 'does?': 0.84; 'subject:Operators': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=kHiTQXAVdHG51Lf93Ao4KntVMyyAqIZ0x2DgndXvTxg=; b=kB7aCMS8dbCtrPSCoiZwwwCY/fUSuSr0lsE2Q37TfYOJtku/UXXTasAh2ja/MQxBsW hWgMaIlahR02z2loq9mOGWrhLnSfjcZxaekMYNkv9lhpFL/Y9fbDV2QdGSjHHUXFEV+m MuCJTugHDTrlq1PWI6qRk78/gIIx4SkwrHBHThd+nKlfAKdr5JIjjR+8bYx+LskHHh2e hxhF7u8pT3q38kEdCj8TJ8k3tLdFZ6jBqhR+x6YDSU5EdbQb7UL2j9ef5fd5QDMl5lsy NEzBW0BbDv0Dh+gIfe+oc8vXyntEdyA6fWnh/89PpMRrQBx9YCJKdjzxpuer6dAhkIsG lk7w==
MIME-Version 1.0
X-Received by 10.50.102.106 with SMTP id fn10mr4744234igb.14.1412256457233; Thu, 02 Oct 2014 06:27:37 -0700 (PDT)
In-Reply-To <9669f493-cfa4-4a84-9f4a-ce3009926ca3@googlegroups.com>
References <9669f493-cfa4-4a84-9f4a-ce3009926ca3@googlegroups.com>
Date Thu, 2 Oct 2014 23:27:37 +1000
Subject Re: Assignment Operators?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14550.1412256465.18130.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412256465 news.xs4all.nl 2942 [2001:888:2000:d::a6]:59279
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3582
X-Received-Body-CRC 2171370882
Xref csiph.com comp.lang.python:78601

Show key headers only | View raw


On Thu, Oct 2, 2014 at 11:24 PM, Didymus <lynto28@gmail.com> wrote:
>>>> errors = False
>>>> errors |= 3
>>>> errors
> 3
>>>> errors |= 4
>>>> errors
> 7
>
>    The '|=' operator, I read should be like a = a | b, but this appears to add the two numbers as long as it's more than the previous:
>
>>>> errors |= 5
>>>> errors
> 7

It is indeed (mostly) equivalent to "a = a | b". Do you understand
what bitwise 'or' does?

When you use False there, it's equivalent to zero. Everything after
that is straight-forward bitwise or.

http://en.wikipedia.org/wiki/Bitwise_operation#OR

ChrisA

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


Thread

Assignment Operators? Didymus <lynto28@gmail.com> - 2014-10-02 06:24 -0700
  Re: Assignment Operators? Chris Angelico <rosuav@gmail.com> - 2014-10-02 23:27 +1000
    Re: Assignment Operators? Grant Edwards <invalid@invalid.invalid> - 2014-10-02 14:23 +0000
  Re: Assignment Operators? Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-02 10:00 -0600
  Re: Assignment Operators? sohcahtoa82@gmail.com - 2014-10-06 14:37 -0700

csiph-web