[Python-ideas] Python 4: Concatenation

Chris Angelico rosuav at gmail.com
Thu Jun 29 19:45:20 EDT 2017


On Fri, Jun 30, 2017 at 9:33 AM, Soni L. <fakedme+py at gmail.com> wrote:
> Step 1. get rid of + for strings, lists, etc. (string/list concatenation is
> not addition)
>
> Step 2. add concatenation operator for strings, lists, and basically
> anything that can be iterated. effectively an overloadable itertools.chain.
> (list cat list = new list, not iterator, but effectively makes
> itertools.chain useless.)
>
> Step 3. add decimal concatenation operator for numbers: 2 cat 3 == 23, 22
> cat 33 = 2233, etc. if you need bitwise concatenation, you're already in
> bitwise "hack" land so do it yourself. (no idea why bitwise is considered
> hacky as I use it all the time, but oh well)

Nope. Practicality beats purity. Something like this exists in REXX
("+" means addition, and "||" means concatenation), and it doesn't
help (though it's necessary there as REXX doesn't have distinct data
types for strings and numbers).

String concatenation might as well be addition. It's close enough and
it makes perfect sense. Get a bunch of people together and ask them
this: "If 5+6 means 11, then what does 'hello' + 'world' mean?". Most
of them will assume it means concatenation.

ChrisA


More information about the Python-ideas mailing list