Boolean result of divmod
Chris Torek
nospam at torek.net
Mon Jun 20 20:38:11 EDT 2011
More information about the Python-list mailing list
Mon Jun 20 20:38:11 EDT 2011
- Previous message (by thread): Boolean result of divmod
- Next message (by thread): Boolean result of divmod
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <261fc85a-ca6b-4520-93ed-27e78bc217fc at y30g2000yqb.googlegroups.com> Gnarlodious <gnarlodious at 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
- Previous message (by thread): Boolean result of divmod
- Next message (by thread): Boolean result of divmod
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list