weak versus dynamic, definitional origins

andrew cooke andrew at acooke.org
Fri May 16 12:24:06 EDT 2003


there are two different things:

 - static or dynamic typing
 - strong and weak typing

you can have them in any combination (static+strong, static+weak,
dynamic+string, dynamic+weak).

static/dynamic relates to whether types are defined in the source.

strong/weak relates to whether types are defined in the runtime
system.

python source doesn't have text describing what type things are, so it
is dynamic.  however, when you run a python program the system keeps
track of different types, so it is strong.  this is how it manages to
make foo*3 do different things depending on whether foo is an integer,
list, or string, for example:

>>> foo = 1
>>> foo * 3
3
>>> foo = [1,2]
>>> foo * 3
[1, 2, 1, 2, 1, 2]
>>> foo = "bar"
>>> foo * 3
'barbarbar'

andrew

Grzegorz Adam Hankiewicz <gradha at titanium.sabren.com> writes:
> I'm not sure about python being strongly and dynamically typed. The
> `strongly' part of the sentence doesn't make sense to me. In Python
> you don't do variable assignment, you do name binding, which means
> the life of a name doesn't need to be the same as the life of the
> object, one of the reasons newcomers don't really understand how
> the __del__ method of objects is not called immediately.
> 
> Whith this scenario there is no strong or weak typing, because
> there is no typing at all. The variable name doesn't have type,
> it can be pointing now at a string object and a few cycles later
> at an integer object. How could be that strong typing?
[...]

-- 
http://www.acooke.org






More information about the Python-list mailing list