Static Typing in Python
jacek.generowicz at cern.ch
Mon Mar 15 13:22:47 CET 2004
Premshree Pillai <premshree_python at yahoo.co.in> writes:
> Err...you probably have the wrong idea of static typing, I think.
Maybe you should check your facts a bit more, before making such bold
> Static typing has to do with explicit declaration (initialization)
> of variables (and not of variable types).
Does it really ?
I suggest you go to an ML or Haskell newsgroup and make that
claim. Come back and report your experience.
(Hint: They are both statically typed languages, and you won't find
many explicit declarations in them.)
(Hint 2: the word "typing" in "static typing" does *not* refer to
pressing keys with your fingers, it refers to the types of objects in
a computer program. See Dang Griffiths' repartee in
<33bd6435fb366a01954fafca8a8f34e3 at news.teranews.com>)
> Python [...] variables are necessarily bound to a particular type.
Are they really ?
>>> a = 3
>>> a = ''
Variables in Python are NOT bound to types[*].
Python variables are bound to objects. Those objects "know" their own
type. So there is an *indirect* association between a variable and a
type. In that sense your statement is correct. There is, however, no
fixed relationship between a variable and a type (which is what
"static" in "static typing" actually means).
> So, Python is dynamically typed, and also strongly
Can't argue with that.
> ...as opposed to statically typed and strongly typed like in C/C++
> (casting notwithstanding).
Acutally, C and C++ are pretty weakly typed (but do bear in mind that
"strongly typed" and "weakly typed" are not well-defined concepts
anyway), even without casting.
[*] Well, they could be bound to types, because Python types are also
a = int
b = dict
c = MyClass
More information about the Python-list