Skip to content

Commit 9f79f17

Browse files
committed
Added a note on list appending/extending
1 parent b4cf877 commit 9f79f17

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ Basics
5959
assert store.a_dictionary['new_value'] == "old value"
6060
assert store.a_dictionary is not store.a_dictionary
6161
62+
# Appending to, extending a list
63+
>>> store.list = [1, 2, 3]
64+
65+
# Because of the fact that .append won't modify the list in the actual file,
66+
# but only a copy...
67+
>>> store.list.append(4)
68+
>>> store.list
69+
[1, 2, 3]
70+
71+
# ... we need to rather use the += operator to append to a list.
72+
>>> store.list += [4]
73+
>>> store.list
74+
[1, 2, 3, 4]
75+
76+
# Similarly, we can extend the list
77+
>>> store.list += [5, 6]
78+
>>> store.list
79+
[1, 2, 3, 4, 5, 6]
80+
6281
Transactions
6382
~~~~~~~~~~~~
6483

0 commit comments

Comments
 (0)