Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98506
| From | "wangq@travelsky.com" <wangq@travelsky.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Re: Question about math.pi is mutable |
| Date | 2015-11-09 08:52 +0800 |
| Message-ID | <mailman.166.1447060810.16136.python-list@python.org> (permalink) |
| References | <CAPTjJmr7brs6B=oD9m2bEk_Mm7wUTVKWU-gxqgAqDLV4diOdzw@mail.gmail.com> |
Hi, Chris Angelico ,
Thank you for your help ! :-)
From: Chris Angelico
Date: 2015-11-06 18:30
To: wangq@travelsky.com
CC: python-list
Subject: Re: Question about math.pi is mutable
On Fri, Nov 6, 2015 at 1:33 PM, wangq@travelsky.com <wangq@travelsky.com> wrote:
> Hello, python-list guys:
>
> I am a newbie of python from Beijing. China.
> I have a question about "math.pi".
> As you can see in the attachment, why i can modify "math.pi"?
> (in "mathmodule.c" "pi" is a "static const double")
>
> Thank you in advance!
>
> Best Wishes!
Simply because, in Python, virtually everything can be changed. You're
welcome to go in and say "math.pi = 3" if you like... and then you
accept the consequences of that.
There are times when you want to change these sorts of 'constants'.
For example, math.pi is a float; but if you're working with
decimal.Decimal everywhere, it might be useful to replace it with a
corresponding Decimal value:
math.pi = decimal.Decimal("3.14159265358979323")
And that's perfectly legal.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Re: Question about math.pi is mutable "wangq@travelsky.com" <wangq@travelsky.com> - 2015-11-09 08:52 +0800
csiph-web