Question about math.pi is mutable

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 6 05:38:10 EST 2015


On Nov 6, 2015 3:20 AM, "wangq at travelsky.com" <wangq at 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.



More information about the Python-list mailing list