Operating environment
ideone (Python 3)
@ Scipy Lecture notes, Edition 2015.2 p14
There is an example of using append () and extend () in the list operation.
L = [ 'red', 'blue', 'green', 'black', 'white' ]
L.append('pink')
...
L.extend(['pink', 'purple']) # extend L, in-place
I've used append () before, but I don't remember extend () very much.
https://docs.python.jp/3/tutorial/datastructures.html 5.1. A little more about list types
list.extend(iterable) Extend the list by adding all the elements of the iterable to the target list. Equivalent to a [len (a):] = iterable.
Try using append () and extend ().
https://ideone.com/CAHncZ
alist = [3, 1, 4]
alist.append([1, 5, 9])
print(alist)
#
blist = [3, 1, 4]
blist.extend([1, 5, 9])
print(blist)
run
[3, 1, 4, [1, 5, 9]]
[3, 1, 4, 1, 5, 9]
+ =
@shiracamus taught me how to add a list using + =
.
Thank you for the information.
Recommended Posts