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


Groups > comp.lang.python > #8041 > unrolled thread

Boolean result of divmod

Started byGnarlodious <gnarlodious@gmail.com>
First post2011-06-20 17:28 -0700
Last post2011-06-20 21:35 -0400
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  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

#8041 — Boolean result of divmod

FromGnarlodious <gnarlodious@gmail.com>
Date2011-06-20 17:28 -0700
SubjectBoolean result of divmod
Message-ID<261fc85a-ca6b-4520-93ed-27e78bc217fc@y30g2000yqb.googlegroups.com>
What is the easiest way to get the first number as boolean?

divmod(99.6, 30.1)

Or do I have to say:

flote, rem=divmod(99.6, 30.1)
bool(flote)

-- Gnarlie

[toc] | [next] | [standalone]


#8042

FromChris Torek <nospam@torek.net>
Date2011-06-21 00:38 +0000
Message-ID<itop5j0rlf@news2.newsguy.com>
In reply to#8041
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

[toc] | [prev] | [next] | [standalone]


#8044

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-21 01:45 +0100
Message-ID<mailman.203.1308617144.1164.python-list@python.org>
In reply to#8041
On 21/06/2011 01:28, Gnarlodious wrote:
> What is the easiest way to get the first number as boolean?
>
> divmod(99.6, 30.1)
>
> Or do I have to say:
>
> flote, rem=divmod(99.6, 30.1)
> bool(flote)
>
divmod returns a tuple, so:

     bool(divmod(99.6, 30.1)[0])

[toc] | [prev] | [next] | [standalone]


#8051

FromTerry Reedy <tjreedy@udel.edu>
Date2011-06-20 21:35 -0400
Message-ID<mailman.207.1308620128.1164.python-list@python.org>
In reply to#8041
On 6/20/2011 8:28 PM, Gnarlodious wrote:
> What is the easiest way to get the first number as boolean?
>
> divmod(99.6, 30.1)
>
> Or do I have to say:
>
> flote, rem=divmod(99.6, 30.1)
> bool(flote)

divmod(x,y) == x//y, x%y

so bool(x//y)

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web