3 ms·
Juxtaposition is not multiplication in this context - you can't write (2 3), for example, it has to be (2 * 3). Furthermore, Python already uses * for strings
by int_19h 5y ago
Juxtaposition is not multiplication in this context - you can't write (2 3), for example, it has to be (2 * 3).
Furthermore, Python already uses * for strings to indicate repetition: ("foo" * 2 == "foofoo").
String concatenation really just needs its own separate operator. & is an obvious candidate, if only it wasn't so commonly appropriated for bitwise AND - which is a very poor use of a single-char operator as it's not something that you need often, especially in a language like Python.
On the other hand, D uses binary ~ for concatenation. That has a neat mnemonic: it's a "rope" that "ties strings together".
- housecarpenter 5y ago& is also used for set intersection in Python. I think + for string concatenation isn't too bad, really. It fits in with the fact that length(s + t) = length(s) + length(t), the same way we write A × B for Cartesian product (since |A × B| = |A| × |B|, even though this operation is neither commutative nor associative) or B^A for a function space (since |B^A| = |B|^|A|).