Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Christian Gollwitzer Newsgroups: comp.lang.python Subject: Re: Question about math.pi is mutable Date: Fri, 6 Nov 2015 20:59:57 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 6 Nov 2015 19:57:50 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="c7f07e460e60d9dab17e15d4f86c3ff0"; logging-data="25007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IpHKg5LC52k+roijLYVMBsDTYYVMUj4c=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: Cancel-Lock: sha1:EqIEG7v5Tb8k/yHXtRmyl9GeZYM= Xref: csiph.com comp.lang.python:98365 Am 06.11.15 um 20:40 schrieb Chris Angelico: > On Sat, Nov 7, 2015 at 6:30 AM, Bartc wrote: >> Is there no way then in Python to declare: >> >> pi = 3.141519 # etc >> >> and make it impossible to override? > > Nope. Even in C++, where classes can define certain things as const, > private, and other such restrictions, you can always get around them > by manipulating pointers appropriately. No, that is not right. If you cast away the constness from a pointer to a constant, you can technically write to that memory, but the behaviour is undefined - another way of saying that the program is illegal. In many cases, the compiler will inline the constant - because you promised, that it can't change - and the update to the constant will not change in all parts of the program: apfelkiste:Tests chris$ cat constub.cpp #include void call_by_ref(const double &v) { std::cout<<"In function: v="<(&pi); *errptr= 0.0; std::cout<<"Now pi is "<