"a better input"
Andrew Dalke
dalke at dalkescientific.com
Fri May 10 22:29:04 EDT 2002
John La Rooy:
>Speaking of which, does this make *sense* ?
>
>>>> l=[]
>>>> l+=(1,2)
>>>> l=l+(3,4)
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
>TypeError: can only concatenate list (not "tuple") to list
Does this make sense?
>>> l = []
>>> l.extend("test")
>>> l
['t', 'e', 's', 't']
>>> l += "ing"
>>> l
['t', 'e', 's', 't', 'i', 'n', 'g']
>>> l + " 1, 2, 3"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can only concatenate list (not "str") to list
>>>
Given [1, 2] + (3, 4) and (1, 2) + [3, 4], what should the
return type be? []? or ()?
Given [1, 2] += (3, 4) this question doesn't arise. += is
the same as extend, and both take an iterable object.
But yes, it did seem strange to me when you wrote it side-by-side
like that.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list