Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98342

Re: Question about math.pi is mutable

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Question about math.pi is mutable
Date Fri, 6 Nov 2015 21:30:16 +1100
Lines 27
Message-ID <mailman.78.1446805818.16136.python-list@python.org> (permalink)
References <201511061033583772468@travelsky.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de EJRBbNzCsfvCsN2kR+oReQJ1xANX84V5vyD7lJPtJYhQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'received:209.85.223': 0.03; 'modify': 0.04; 'newbie': 0.05; 'subject:Question': 0.05; 'cc:addr:python-list': 0.09; 'python': 0.10; 'advance!': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sorts': 0.16; 'value:': 0.16; 'wrote:': 0.16; '(in': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'header :In-Reply-To:1': 0.24; 'fri,': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'decimal': 0.29; 'that.': 0.30; 'useful': 0.33; 'received:google.com': 0.35; 'nov': 0.35; 'replace': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209': 0.38; 'thank': 0.38; 'why': 0.39; 'hello,': 0.40; 'times': 0.63; 'python-list': 0.66; 'virtually': 0.66; 'china.': 0.79; 'chrisa': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=KIHUx4DVlGDbLMKusux2N0Y2j5se9d4vkxLeRoULzRM=; b=gnpOcxexSwLuaJDbGOe8d/a51S3YBLCsO3US7PpmXq/5ZToq3j0Q0oAb4pjdefrJ5x uVKTPAa/70HC9EU1Z6WrkLoqQ60SNdtZc+3mP59UrtsV5zFT3LvQ2+JEGMBniXgRMGEx jzmZ1qjoM/pNeRzYKnZEGZ1bXEDgeXQKtBiv8vUY+ph0hvHfT5ody4S6XZqGmQ6M1j/B JHM5qp1ahTABvrsLFjgHMkFgB8liX9EisjIgySrOJJQyWz2Zm1QfgDgvpIG0HTAgg1VN CHnr1cJMFlv88gKPxoNIF/jgJqkBpF6Dirq+9s5p/mZELSo/bLNQvjEbWunl+QMRELfc +3sA==
X-Received by 10.107.16.84 with SMTP id y81mr5780426ioi.19.1446805816337; Fri, 06 Nov 2015 02:30:16 -0800 (PST)
In-Reply-To <201511061033583772468@travelsky.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:98342

Show key headers only | View raw


On Fri, Nov 6, 2015 at 1:33 PM, wangq@travelsky.com <wangq@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")
>
> Thank you in advance!
>
> Best Wishes!

Simply because, in Python, virtually everything can be changed. You're
welcome to go in and say "math.pi = 3" if you like... and then you
accept the consequences of that.

There are times when you want to change these sorts of 'constants'.
For example, math.pi is a float; but if you're working with
decimal.Decimal everywhere, it might be useful to replace it with a
corresponding Decimal value:

math.pi = decimal.Decimal("3.14159265358979323")

And that's perfectly legal.

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Question about math.pi is mutable Chris Angelico <rosuav@gmail.com> - 2015-11-06 21:30 +1100
  Re: Question about math.pi is mutable Marko Rauhamaa <marko@pacujo.net> - 2015-11-06 14:55 +0200

csiph-web