[issue39964] adding a string to a list works differently with x+='' compared to x=x+''

2020-03-14 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

That's not a bug. The in-place addition `+=` for lists is equivalent to the 
extend method. See the documentation:

https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

and the tutorial:

https://docs.python.org/3/tutorial/datastructures.html

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39964] adding a string to a list works differently with x+='' compared to x=x+''

2020-03-14 Thread Richard King


New submission from Richard King :

x = ['a']

x += ' ' results in ['a',' ']

x = x + ' ' results in an exception:
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate list (not "str") to list

It behaves the same in 2.7.15 and 3.7.2.

--
components: Windows
messages: 364213
nosy: paul.moore, rickbking, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: adding a string to a list works differently with x+='' compared to x=x+''
type: behavior
versions: Python 2.7, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com