DEV Community

Discussion on: C++ Variables, Functions, Conditionals, and Logic. In VSCode.

Collapse
 
pgradot profile image
Pierre Gradot

Python is not untyped. It is dynamically and strongly typed.

Example:

>>> s = "hello"
>>> type(s)
<class 'str'>
>>> s + 3
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    s + 3
TypeError: can only concatenate str (not "int") to str
>>> s = 3
>>> type(s)
<class 'int'>
Enter fullscreen mode Exit fullscreen mode

We can change the type of s -> dynamic typing

We cannot add a string and a number -> strong typing

Collapse
 
dynamicsquid profile image
DynamicSquid

I thought untyped meant the same as dynamically typed? Like "untyped" not in the sense that there are no types, but "untyped" in the sense that variables aren't bound to a certain type

Thread Thread
 
pgradot profile image
Pierre Gradot • Edited

In that way, I agree. This discussion is interesting: stackoverflow.com/questions/915438... It validates this usage, but it also says that it is a not-so-accurate shortcut.

In my opinion, "untyped" can also refer to cases where there is really "no type". In C++, it is often the case when deal with raw bytes (they are untyped on their own, you can interpret then the way you want) or when you use assembly code (a register simply holds a number, it could be either an int or an enum that fits in an int).

That's why I prefer to use "dynamically typed" when types are actually checked by the language : )