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


Groups > comp.lang.python > #98344

Re: Question about math.pi is mutable

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Question about math.pi is mutable
Date 2015-11-06 03:38 -0700
Message-ID <mailman.80.1446806298.16136.python-list@python.org> (permalink)
References <201511061033583772468@travelsky.com>

Show all headers | View raw


On Nov 6, 2015 3:20 AM, "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")

Like all floats, math.pi is immutable. However, the *name* pi in the math
module is not special and can be rebound to a new value, like (almost) any
other name.

So yes, you can assign 3 to math.pi. You can also assign 3 to math.sqrt, or
os.urandom, or float.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about math.pi is mutable Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-06 03:38 -0700

csiph-web