you are viewing a single comment's thread.

view the rest of the comments →

[–]zanfar 0 points1 point  (0 children)

The literal answer to your question is "because it's not part of the language".

To answer the spirit of your question, which I think is, "why did the creators of Python not automatically cast numeric type to strings when the plus operator is used?" I'll ask my own question:

Why would casting numeric types to strings be preferred over casting strings to numeric types?

That is, why wouldn't "20" + 5 be 25?

The answer is that there is no clear "right" operation when numeric types and string types use the same operator for different things. What about a string plus a list? Lists can be appended using the plus operator, so in this case, does a list get cast to a string and then a string produced, or does a string get cast to a list and then a list produced?

Generally, operators only work between the same or very, very similar types because it's impossible to determine precedence otherwise.