Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8042
| From | Chris Torek <nospam@torek.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Boolean result of divmod |
| Date | 21 Jun 2011 00:38:11 GMT |
| Organization | None of the Above |
| Lines | 26 |
| Message-ID | <itop5j0rlf@news2.newsguy.com> (permalink) |
| References | <261fc85a-ca6b-4520-93ed-27e78bc217fc@y30g2000yqb.googlegroups.com> |
| NNTP-Posting-Host | pb4044125c39bb60257c85ac258da8105a64b2fc8128dd39d.newsdawg.com |
| X-Newsreader | trn 4.0-test76 (Apr 2, 2001) |
| Originator | torek@elf.torek.net (Chris Torek) |
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!news.ecp.fr!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!not-for-mail |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8042 |
Show key headers only | View raw
In article <261fc85a-ca6b-4520-93ed-27e78bc217fc@y30g2000yqb.googlegroups.com>
Gnarlodious <gnarlodious@gmail.com> wrote:
>What is the easiest way to get the first number as boolean?
>
>divmod(99.6, 30.1)
divmod returns a 2-tuple:
>>> divmod(99.6,30.1)
(3.0, 9.2999999999999901)
Therefore, you can subscript the return value to get either
element:
>>> divmod(99.6,30.1)[0]
3.0
Thus, you can call bool() on the subscripted value to convert
this to True-if-not-zero False-if-zero:
>>> bool(divmod(99.6,30.1)[0])
True
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Boolean result of divmod Gnarlodious <gnarlodious@gmail.com> - 2011-06-20 17:28 -0700 Re: Boolean result of divmod Chris Torek <nospam@torek.net> - 2011-06-21 00:38 +0000 Re: Boolean result of divmod MRAB <python@mrabarnett.plus.com> - 2011-06-21 01:45 +0100 Re: Boolean result of divmod Terry Reedy <tjreedy@udel.edu> - 2011-06-20 21:35 -0400
csiph-web