Documentation, assignment in expression.

Devin Jeanpierre jeanpierreda at gmail.com
Mon Mar 26 10:52:13 CEST 2012


On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm
<kiuhnm03.4t.yahoo.it at mail.python.org> wrote:
> On 3/25/2012 15:48, Tim Chase wrote:
>>
>> The old curmudgeon in me likes the Pascal method of using "=" for
>> equality-testing, and ":=" for assignment which feels a little closer to
>> mathematical use of "=".
>
>
> Unfortunately, ":=" means "is defined as" in mathematics. The "right"
> operator would have been "<-".


"Is defined as" is actually pretty reasonable. "Define this to be
that" is a common way to speak about assignment. Its only difference
is the present tense. For example, in Python, "def" stands for
"define", but we can overwrite previous definitions::

    def f(x): return x
    def f(x): return 2
    f(3) == 2

In fact, in pretty every programming language that I know of with a
"define" assignment verb, this is so. For example, in Scheme, x is 2
at the end::

    (define x 1)
    (define x 2)
    x

-- Devin



More information about the Python-list mailing list