How well do you know Python?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Jul 5 04:22:48 EDT 2016
On Tuesday 05 July 2016 16:38, Chris Angelico wrote:
> On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> What happens in this code snippet?
>>
>> L = [1]
>> t = (L,)
>> t[0] += 1
>>
>> Explain what value t has, and why.
>
> Not sure you have that question right, because it simply gives a
> TypeError. You can't add an integer to a list.
D'oh!
Try this instead:
t = ([0],)
t[0] += [1]
--
Steve
More information about the Python-list
mailing list