undefined variable

Alex Martelli aleaxit at yahoo.com
Sun Jan 28 05:59:09 EST 2001


"Aahz Maruch" <aahz at panix.com> wrote in message
news:94tq9d$7mb$1 at panix2.panix.com...
> In article <nHsc6.252522$59.63479549 at news3.rdc1.on.home.com>,
> shaka <fabrice.n at home.com> wrote:
> >
> > hi, I am a beginner learning python, and I have notice that in python
> >variale are not declared or defined. But does it mean that your cannot
use
> >the same variable twice and all your variable have to be of different
name.
> >In java you can have a variable of the same name but of different type
and
> >it makes programming much more flexible.
>
> Python variables can hold any data type.  Also, I could be wrong, but I
> doubt that Java supports name overloading for variables; I believe name
> overloading only applies to functions.

Yes, overloading DOES only apply to methods (aka functions) in Java.

Further, Java *explicitly forbids* a local variable 'shadowing' one in
a lexically-outer block -- because the language designers considered
such a practice too error-prone (I think they DO have a point!).

So, I'm at all not sure what shaka means here, throughout his 2nd
and 3rd sentences: you _can_ use homonym variables in Python, on
essentially the same terms as you can in Java, i.e., that they be in
different scopes (when Python scopes nest, if I read the PEP correctly,
you will also be able to do 'shadowing' in Python -- which may be a
pity, but, oh well); how such a practice "makes programming much
more flexible", I don't know -- it hardly seems a major issue!


Alex






More information about the Python-list mailing list