This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author py.user
Recipients docs@python, py.user
Date 2011-07-23.01:39:57
SpamBayes Score 5.406496e-07
Marked as misclassified No
Message-id <1311385198.6.0.560721842501.issue12617@psf.upfronthosting.co.za>
In-reply-to
Content
1)
4.6.4 Mutable Sequence Types

| s[i:j] = t |  slice of s from i to j is replaced |
|            |  by the contents of the iterable t  |


>>> lst = list('abc')
>>> barr = bytearray(b'abc')
>>> lst[:1] = 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable
>>> barr[:1] = 4
>>> barr
bytearray(b'\x00\x00\x00\x00bc')
>>>

there is no info about this feature in the documentation

2)
4.6.4 Mutable Sequence Types

| s.extend(x) |  same as s[len(s):len(s)] = x |

>>> lst = list('abc')
>>> barr = bytearray(b'abc')
>>> lst.extend(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> barr.extend(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> lst[len(lst):len(lst)] = 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable
>>> barr[len(barr):len(barr)] = 4
>>> barr
bytearray(b'abc\x00\x00\x00\x00')
>>>

barr.extend(x)  !=  barr[len(barr):len(barr)] = x
History
Date User Action Args
2011-07-23 01:39:58py.usersetrecipients: + py.user, docs@python
2011-07-23 01:39:58py.usersetmessageid: <1311385198.6.0.560721842501.issue12617@psf.upfronthosting.co.za>
2011-07-23 01:39:57py.userlinkissue12617 messages
2011-07-23 01:39:57py.usercreate