typed variables (WAS re.compile.match() results ...)

Steven Bethard steven.bethard at gmail.com
Thu Nov 11 18:38:14 CET 2004


Stefan Seefeld <seefeld <at> sympatico.ca> writes:
> 
> Scott David Daniels wrote:
> > Axel Bock wrote:
> > 
> > This shows a misunderstanding.  Python does not have typed variables.
> 
> huh ? It is perfectly valid to ask what type a variable has, i.e. python
> is 'strongly typed'.

I think perhaps Axel Bock was getting a little pedantic here.  Technically
Python does not have typed variables; any "variable" in Python can hold an
object of any type.  Hence examples like:

>>> a = 'a'
>>> a = 4.5

Probably a better way of saying this is to say that *names* in Python can be
*bound* to objects of any type.  Of course, Python is strongly typed, so the
objects 'a' or 4.5 will not change type on you, though you are free to bind any
name you like to these objects:

>>> a = b = c = 'a'
>>> a is b
True
>>> b is c
True
>>> a, b, c
('a', 'a', 'a')

I think Axel Bock would have been happier if the sentence:

"now a,b,c,d are all string variables, and they all come out as unicode strings"

had been expressed as something like:

"now the names a,b,c,d are all bound to unicode objects"

Steve




More information about the Python-list mailing list