4 ms·
'+' works great as a concatenation operator, so long as you don't ever try to implicitly convert the values. Case in point - Python: >>> 1+2 3 >>> "1"+"2
by int_19h 11y ago
'+' works great as a concatenation operator, so long as you don't ever try to implicitly convert the values. Case in point - Python:
>>> 1+2
3
>>> "1"+"2"
'12'
>>> "1"+2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
- kbenson 11y agoThose are literals, not variables. My whole argument is about the ambiguity introduced when you are implicitly coercing variables. But yes, if the language does not coerce between string and numeric types, it's a non-issue. I'm specifically talking about supporting coercion but continuing to use '+' for concatenation of strings (and ==/!= for equivalence testing of strings as well).