Differences between revisions 2 and 7 (spanning 5 versions)
Revision 2 as of 2008-08-12 01:25:51
Size: 625
Editor: AlexMartelli
Comment:
Revision 7 as of 2008-08-12 22:34:01
Size: 2269
Editor: MichaelFoord
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
People often use the term strongly-typed language to refer to a language that is both statically typed (types are associated with a variable declaration -- or, more generally, the compiler can tell which type a variable refers to, for example through type inference, without executing the program) and strongly-typed (restrictive about how types can be intermingled). So, if you look at dynamic typing and strong-typing as orthogonal concepts, Python can be both dynamically and strongly typed. SEE:'''[wiki:Ten_things_people_want_to_know_about_Python Ten things people want to know about Python]'''for more details.
Line 3: Line 3:
See [http://en.wikipedia.org/wiki/Strongly-typed_programming_language Strongly Typed Programming Language] for more details.  Answer::
  * People often use the term strongly-typed language to refer to a language that is both statically typed (types are associated with a variable declaration -- or, more generally, the compiler can tell which type a variable refers to, for example through type inference, without executing the program) and strongly-typed (restrictive about how types can be intermingled). So, if you look at dynamic typing and strong-typing as orthogonal concepts, Python can be both dynamically and strongly typed.

Another answer:
 * Python is strongly typed as the interperter keeps track of all variables types. It's also very dynamic as it rarely uses what it knows to limit variable usage. In Python, it's the program's responsibility to use built-in functions like isinstance() and issubclass() to test variable types and correct usage. Python tries to stay out of your way while giving you all you need to implement strong type checking.

And another one:
 * In a weakly typed language a compiler / interpreter will sometimes change the type of a variable. For example, in some languages (like Perl) you can add strings to numbers 'x' + 3 becomes 'x3'. This can be a problem because if you have made a mistake in your program, instead of raising an exception execution will continue but your variables now have wrong and unexpected values. In a strongly typed language (like Python) you can't perform operations inappropriate to the type of the object - attempting to add numbers to strings will fail. Problems like these are harder to diagnose because the exception is raised at the point where the error occurs rather than at some other, potentially far removed, place.

 * In a statically typed language, the type of variables must be known (and usually declared) at the point at which it is used. Attempting to use it will be an error. In a dynamically typed language, objects still have a type, but it is determined at runtime. You are free to bind names (variables) to different objects with a different type. So long as you only perform operations valid for the type the interpreter doesn't care what type they actually are.

SEE:[wiki:Ten_things_people_want_to_know_about_Python Ten things people want to know about Python]for more details.

Answer
  • People often use the term strongly-typed language to refer to a language that is both statically typed (types are associated with a variable declaration -- or, more generally, the compiler can tell which type a variable refers to, for example through type inference, without executing the program) and strongly-typed (restrictive about how types can be intermingled). So, if you look at dynamic typing and strong-typing as orthogonal concepts, Python can be both dynamically and strongly typed.

Another answer:

  • Python is strongly typed as the interperter keeps track of all variables types. It's also very dynamic as it rarely uses what it knows to limit variable usage. In Python, it's the program's responsibility to use built-in functions like isinstance() and issubclass() to test variable types and correct usage. Python tries to stay out of your way while giving you all you need to implement strong type checking.

And another one:

  • In a weakly typed language a compiler / interpreter will sometimes change the type of a variable. For example, in some languages (like Perl) you can add strings to numbers 'x' + 3 becomes 'x3'. This can be a problem because if you have made a mistake in your program, instead of raising an exception execution will continue but your variables now have wrong and unexpected values. In a strongly typed language (like Python) you can't perform operations inappropriate to the type of the object - attempting to add numbers to strings will fail. Problems like these are harder to diagnose because the exception is raised at the point where the error occurs rather than at some other, potentially far removed, place.
  • In a statically typed language, the type of variables must be known (and usually declared) at the point at which it is used. Attempting to use it will be an error. In a dynamically typed language, objects still have a type, but it is determined at runtime. You are free to bind names (variables) to different objects with a different type. So long as you only perform operations valid for the type the interpreter doesn't care what type they actually are.

Why is Python a dynamic language and also a strongly typed language (last edited 2012-02-24 13:34:06 by 87-119-185-195)

Unable to edit the page? See the FrontPage for instructions.