Python Strings
Keith Ray
k_j_r_a_y at ix.netcom.com
Wed Sep 6 11:00:40 EDT 2000
In article <slrn8rc5mm.p3f.scarblac-spamtrap at flits104-37.flits.rug.nl>,
scarblac-rt at pino.selwerd.nl wrote:
[...]
>Objects can't change type, immutable objects can't even change value.
Right.
>So in Python you can always find out the type of the object a variable
>refers to, and still assign another object to the variable, and I'd still
>call it strictly typed.
Not!
>The problem is that assignment is different from other languages.
Not!
[...]
This is about the most alien perspective on "typing" I've seen, but it
always seems to come up whenever someone asks about strongly/weakly
typed languages.
What most people mean by "strongly-typed" or "staticly typed" is "there
is compile-time checking of variable types" (and parameter-types, and
function-return-types and expressions being assigned or passed into
variables/parameters/etc.).
What most people mean by "weakly-typed" or "dynamically typed" is "there
is only run-time checking of variable types" (and parameter-types, and
function-return-types and expressions being assigned or passed into
variables/parameters/etc.).
C is a language that is staticly typed -- but the parameter types for
non-prototyped function are not checked by the compiler, making C one of
the most dangerous language in which to be a sloppy programmer.
Python and Smalltalk are not staticly typed, because you don't declare
the types for variables, parameters, and function-return-values. You can
assign any type of object to a variable, and assign a completely
different type of object to the same variable in the next line, and the
compiler does not complain. If you pass a list into a function-parameter
where the function is expecting an floating-point-scalar, then you will
most likely have a run-time error.
C++ and Java are staticly typed -- you declare a type for a variable. If
you try to assign the wrong type to it, the compiler complains at
compile-time. If you try to pass an array into a function that is
expecting a floating-point-scalar, then the compiler will give you an
error at compile time.
Some uncommon languages have a 'type-inferencing' system, so despite the
fact that variables, parameters, and function-return-values are not
given type declarations in those languages, the types can be inferred
and checked at compile time.
--
<http://pw2.netcom.com/~kjray/>
More information about the Python-list
mailing list