Why must Python list addition be homogenous?
问题 Can anyone familiar with Python's internals (CPython, or other implementations) explain why list addition is required to be homogenous: In [1]: x = [1] In [2]: x+"foo" --------------------------------------------------------------------------- TypeError Traceback (most recent call last) C:\Users\Marcin\<ipython-input-2-94cd84126ddc> in <module>() ----> 1 x+"foo" TypeError: can only concatenate list (not "str") to list In [3]: x+="foo" In [4]: x Out[4]: [1, 'f', 'o', 'o'] Why shouldn't the x+