Sadly, a lot of Java people have been going around saying that "Java is strongly typed" and "Python is weakly typed".

These folks pretty much don't understand the meanings of the terms.

Java is:

Property of type system

Meaning
Manifestly typed You have to explicitly state your variable types
Statically typed Types are assigned at compile time
Mostly strongly typed Few types are converted implicitly. One obvious exception is that integers can be added to strings

Python is:

Property of type system

Meaning
Dynamically typed "Type" is an attribute of a value, not of a variable. Types are assigned at run time, not compile time
Mostly strongly typed Few types are converted implicitly. The chief exception is that almost anything can be used in a boolean context

Furthermore, Python may be:

Type system

What it does for you

Addons that provide it
Implicitly typed Types are inferred and checked before run time. Pylint, pyflakes or similar tool
Gradually typed Some or all of your variables may be manifestly typed Mypy

  • Here is an example of Java implicitly converting type. Java allows this, to the detriment of code correctness. It doesn't raise an exception, so even a unit test might not catch it.
  • Here is Python3 doing the same thing, but raising an exception because the types do not match up. Sadly, pylint and pyflakes do not catch the error, but at least a unit test would.


    Hits: 931
    Timestamp: 2024-02-29 11:34:30 PST

    Back to Dan's tech tidbits

    You can e-mail the author with questions or comments: