Question about math.pi is mutable

Lorenzo Sutton lorenzofsutton at gmail.com
Fri Nov 6 11:12:07 EST 2015



On 06/11/2015 13:30, Bartc wrote:
> 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.)

Still nothing stops you from doing:

math.sin = 0

If you really want to?



More information about the Python-list mailing list