static, dynamic, strong and weak (was RE: PEP 285: Adding a bool type)

Ken Seehof kseehof at neuralintegrator.com
Tue Apr 9 18:57:01 EDT 2002


Roy wrote:
>  tanzer at swing.co.at (Christian Tanzer) wrote:
> > There are several dimensions to typing, including:
> > - static vs. dynamic
> > - strong vs. weak
> 
> Putting it another way...
> 
> In Perl, if I write "$x = 1;", x can act as either an integer or 
> a string, 
> depending on how I use it.
> 
> In Python, if I write "x = 1", x can only act as an integer.  In that 
> sense, it's strongly typed.  On the other hand, it's also true that 
> sometimes later, I can say "x = '1'", and now x can only act as a 
> string.  
> At any particular point in time, its type is strongly defined, 
> but the type 
> can also (dynamically) change from time to time.
> 
> In Python, the variable (x) can change type, but the value itself (1) 
> cannot.  In Perl, the value itself can change type as coerced by the 
> context.

Python is mostly strongly typed.  Within the context of numbers, I
would classify python as weakly typed in the sense that x = 1 can act
as a float, int, longint, or bool, depending on context.  All numbers
of equal value are pretty much interchangable (this becomes more true
as we add more numeric unification features).  In c/c++ numbers are
more strongly typed, in that there are many ways to get error messages
for using the wrong type of number without explicit conversion.

The fact that an object's type doesn't actually change seems like an
implementation detail to me.  Numbers in python -feel- as if they are
weakly typed.

On the other hand, the ability to typecast pointers makes c/c++ rather
weakly typed compared to python on the whole.

- Ken Seehof






More information about the Python-list mailing list