Documentation, assignment in expression.
Kiuhnm
kiuhnm03.4t.yahoo.it
Mon Mar 26 06:56:30 EDT 2012
On 3/26/2012 10:52, Devin Jeanpierre wrote:
> 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
When you write
(define x 1)
(define x 2)
x
or, in F# and OCaml,
let x = 1
let x = 2
x
you're saying
x = 1
{
x = 2
x
}
You don't modify 'x': you hide it by defining another "value" (not
variable) with the same name.
Indeed,
let x = 1
let x = 2
x
is shorthand for
let x = 1 in
let x = 2 in
x
Kiuhnm
More information about the Python-list
mailing list