Message140924
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 |
|
Date |
User |
Action |
Args |
2011-07-23 01:39:58 | py.user | set | recipients:
+ py.user, docs@python |
2011-07-23 01:39:58 | py.user | set | messageid: <1311385198.6.0.560721842501.issue12617@psf.upfronthosting.co.za> |
2011-07-23 01:39:57 | py.user | link | issue12617 messages |
2011-07-23 01:39:57 | py.user | create | |
|