Question about math.pi is mutable

Bartc bc at freeuk.com
Fri Nov 6 07:30:29 EST 2015


On 06/11/2015 02:33, 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")

Python isn't C.

Your attachment isn't visible, but it can be demonstrated easily:

import math

math.pi=0

print (math.pi)

In Python, presumably 'pi' is just another variable, and variables can 
be written to.

(Perhaps math.pi would be better off as a function.)

-- 
Bartc




More information about the Python-list mailing list