def foo():
return 1 + "2"
Another example showing Python is untyped: x = 1
x = "2"
x clearly has no type. No variables in python have types. def foo():
return 1 + "2"
Another example showing Python is untyped: x = 1
x = "2"
x clearly has no type. No variables in python have types.Your first example demonstrates that python does not have compile time type checking
Your second example demonstrates that python variables can dynamically change types.
>>> 1 + "2"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
https://dev.to/jiangh/type-systems-dynamic-versus-static-str...The program '1 + "2"' is a perfectly valid python program with well defined behavior (it signals a TypeError). This demonstrates that you can in fact add integers to strings in python. Of course whether or not you can add integers to strings is completely orthogonal to whether or not a language is typed. Both typed and untyped languages may overload the addition operator.
"A type system is a tractable syntactic method ... Terms like 'dynamically typed' are arguably misnomers."
https://stackoverflow.com/questions/9154388/does-untyped-als...
I still prefer the term dynamically typed, because there are useful distinctions about value types to be made among such languages, such as those described in striking's link.
It's like the discussion is untyped, and the downvotes are runtime errors that would have been caught if terms were agreed upon ahead of time.