Differences between revisions 5 and 6
Revision 5 as of 2008-08-12 22:05:44
Size: 1637
Editor: MichaelFoord
Comment:
Revision 6 as of 2008-08-12 22:31:24
Size: 1807
Editor: MichaelFoord
Comment:
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:
 * 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.  * 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.

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.

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.