Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78601
| References | <9669f493-cfa4-4a84-9f4a-ce3009926ca3@googlegroups.com> |
|---|---|
| Date | 2014-10-02 23:27 +1000 |
| Subject | Re: Assignment Operators? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14550.1412256465.18130.python-list@python.org> (permalink) |
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
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