Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Dickinson Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Mon, 23 May 2016 20:17:44 +0000 (UTC) Lines: 32 Message-ID: References: <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> <57422e03$0$1596$c3e8da3$5496439d@news.astraweb.com> <85r3ct9zt2.fsf@benfinney.id.au> <5742bacb$0$1526$c3e8da3$5496439d@news.astraweb.com> <87zirgrgol.fsf@bsb.me.uk> <87oa7wra4d.fsf@bsb.me.uk> <87d1ocr1kn.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de gF1/jH/5AQNdIH5KSc/D3g1/+3DBFbMEYepeDHXlCl1Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'float': 0.05; 'method.': 0.05; 'that?': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'python': 0.10; 'options.': 0.15; 'result.': 0.15; 'decimal.': 0.16; 'hexadecimal': 0.16; 'message-id:@post.gmane.org': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'stored.': 0.16; 'subject:make': 0.16; 'numerical': 0.18; '>>>': 0.20; 'fraction': 0.22; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'actual': 0.28; 'convert': 0.29; 'print': 0.30; 'probably': 0.31; '[1]': 0.32; 'class': 0.33; 'displays': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:org': 0.37; 'hundreds': 0.37; 'charset :us-ascii': 0.37; 'skip:p 20': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'some': 0.40; 'show': 0.62; 'subject: / ': 0.63; 'here': 0.66; 'expert': 0.70; 'stored,': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 81.101.15.24 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> <57422e03$0$1596$c3e8da3$5496439d@news.astraweb.com> <85r3ct9zt2.fsf@benfinney.id.au> <5742bacb$0$1526$c3e8da3$5496439d@news.astraweb.com> <87zirgrgol.fsf@bsb.me.uk> <87oa7wra4d.fsf@bsb.me.uk> <87d1ocr1kn.fsf@bsb.me.uk> Xref: csiph.com comp.lang.python:109023 Ben Bacarisse bsb.me.uk> writes: > [1] Not being a Python expert I don't know how you show that actual > value of a float. What is the Pythonic way to do that? I don't know about Pythonic, but here are some options. 1. Convert the float to Decimal, and print the result. This shows the exact binary value that's stored, but displays it in decimal. Be aware that the result will be hundreds of digits long for very large or very small floats. >>> print(Decimal(pi)) 3.141592653589793115997963468544185161590576171875 2. If you're happy with a hexadecimal representation, use the float.hex method. Again, this shows the exact value stored. >>> print(pi.hex()) 0x1.921fb54442d18p+1 3. To get an equivalent fraction, convert to the fractions.Fraction type or use the as_integer_ratio method. >>> from fractions import Fraction >>> print(Fraction(pi)) 884279719003555/281474976710656 >>> print(pi.as_integer_ratio()) (884279719003555, 281474976710656) -- Mark (who should probably take a numerical methods class someday)