0

It is clear to me that Python is dynamically typed and that dynamic versus static typing is independent from strongly versus weakly typed. (Just to get possible confusion out of the way.)

Wikipedia gives the addition of a string and an integer as an example: You can't do it in strongly typed languages. But in Python you can do: "string"*3 which clearly isn't duck typing either. Is that just a single exception to the general rule or is Python not really strongly typed? Or did I not comprehend the definition of weak vs strong well enough? Pleas enlighten me.

Edit: as I have been prompted to give my definition of what strongly typed means I understand that it is defined as not being able to intermix data types in operations. What confuses me is that wikipedia gives the impossibility of adding a string and an int as example why python is strongly typed the multiplication of them is possible and that would constitute in my interpretation an example why it is weakly typed. I only mentioned duck typing because it seems to create an exception in that you can intermix data types as long as they look and behave the same. (Which strings and ints clearly not do.)

edit2: I also think this isn't duplicate because the other question actually is about static/dynamic typing.

blues
  • 4,547
  • 3
  • 23
  • 39
  • This kind of "syntactic sugar" could be implemented in eg. C++ as well, nothing special about it. It does not really has to do if the language is strictly typed or duck typed or whatever. – Niklas R Mar 12 '13 at 21:45
  • Duck typing is not strong typing... rather the opposite. – Markus Unterwaditzer Mar 12 '13 at 21:45
  • 1
    `"string"*3` is not addition. I think you need to define what *you* mean by strong and weak. Everyone has a different definition. – David Heffernan Mar 12 '13 at 21:47
  • 1
    _Duck typing_ has nothing to do with the _type_ system at all. It is a matter to describe a class or object by it's members and methods. – Octavian Helm Mar 12 '13 at 21:47
  • 1
    ["Strongly typed" is **meaningless**](http://stackoverflow.com/a/9929697/395760). Many definitions of "strong typing" include Python's behavior, and many other definitions do not. None of these definitions has any clear advantage, significant mind share, or claim to correctness. Just forgo the term altogether. –  Mar 12 '13 at 21:54
  • The same Wikipedia page you quote defines as strong typed a language which "specifies one or more restrictions on how operations involving values of different data types can be intermixed." That's it. No mention of which restrictions make a language strong typed; no mention of constraints that need to be enforced (e.g. `"Hello" * 3`) as a consequence of other constraints being already enforced (e.g. `"Hello" + 3`). Python specifies a restriction on a single operation (e.g. `+`) involving values different types (e.g. `str` and `int`) and that's enough to define it strong typed. – Giulio Piancastelli Mar 12 '13 at 21:56

0 Answers0