Curious assignment behaviour

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Oct 22 11:44:27 EDT 2001


Mon, 22 Oct 2001 13:48:46 +0200, Nomad <nomad***@***freemail.absa.co.za> pisze:

>>It depends on the language. There are languages where 'let x = y'
>>introduces the name x, defined as y, and its value can't change.
> 
> But, surely, if (as you mention above) x is introduced
> (defined/dimensioned... whatever), then x's value _will_ be changed
> from (in python terms) None to that defined in y?

No. Python, as most languages, distinguishes between a nonexistant
variable and a variable bound to None.

Introducing a local variable which shadows any previous meaning of
the given identifier (if any) is not the same as changing the value
of the variable. It's a completely new variable, indepepdent from any
previous meaning of the given identifier.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list