Question about math.pi is mutable
Terry Reedy
tjreedy at udel.edu
Fri Nov 6 20:49:17 EST 2015
On 11/6/2015 5:26 PM, Thomas 'PointedEars' Lahn wrote:
> Bartc wrote:
>> import math
>>
>> math.pi=0
>>
>> print (math.pi)
>>
>> In Python, presumably 'pi' is just another variable, and variables can
>> be written to.
>
> “pi” is the name of an attribute of the module object referred to by “math”.
>
>> (Perhaps math.pi would be better off as a function.)
>
> Perhaps not. Calling a function includes an overhead that one does not want
> in already costly floating-point calculations.
>
> In my opinion, mathematical constants should be implemented as constants
> (non-overwritable, non-deletable, throwing exceptions when attempting to do
> either) but apparently the authors of math.py disagree.
One of multiple discussions of the 'constants' idea.
bugs.python.org/issue1465406
It is mostly about speed.
--
Terry Jan Reedy
More information about the Python-list
mailing list