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


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

Re: Question about math.pi is mutable

Started byChris Angelico <rosuav@gmail.com>
First post2015-11-06 21:30 +1100
Last post2015-11-06 14:55 +0200
Articles 2 — 2 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Question about math.pi is mutable Chris Angelico <rosuav@gmail.com> - 2015-11-06 21:30 +1100
    Re: Question about math.pi is mutable Marko Rauhamaa <marko@pacujo.net> - 2015-11-06 14:55 +0200

#98342 — Re: Question about math.pi is mutable

FromChris Angelico <rosuav@gmail.com>
Date2015-11-06 21:30 +1100
SubjectRe: Question about math.pi is mutable
Message-ID<mailman.78.1446805818.16136.python-list@python.org>
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

[toc] | [next] | [standalone]


#98350

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-11-06 14:55 +0200
Message-ID<87k2pvi8yj.fsf@elektro.pacujo.net>
In reply to#98342
Chris Angelico <rosuav@gmail.com>:

> 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.

How far cosmology would have evolved by now if Albert Einstein had had
Python at his disposal. He could simply have been able to experiment
with different values of the Cosmological Constant and seen the effects
around him in the room.


Marko

[toc] | [prev] | [standalone]


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


csiph-web