Python> list> extend () or + =

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1233 / 12833)

There was an example of adding a list with extend () or + =.

I made a code with ideone.

http://ideone.com/CVLeBv

alist = ['7of9', 'Kim', 'Janeway']
print(alist)
alist.extend(["B'Elanna"])
print(alist)
alist += ['Chakotay']
print(alist)

result


Success	time: 0 memory: 9024 signal:0
['7of9', 'Kim', 'Janeway']
['7of9', 'Kim', 'Janeway', "B'Elanna"]
['7of9', 'Kim', 'Janeway', "B'Elanna", 'Chakotay']

Two methods (extend () or + =) are provided for one process.

It may be useful to have a choice when the code format is consistent.

Recommended Posts

Python> list> extend () or + =
[Python] list
Python basics: list
Python> Comprehension / Comprehension> List comprehension
Python list manipulation
OR the List in Python (zip function)
Sorted list in Python
Python Exercise 2 --List Comprehension
List of python modules
Python list comprehension speed
Filter List in Python
Python from or import
python autotest or sniffer
python unittest assertXXX list
Python3 List / dictionary memo
[Memo] Python3 list sort
OpenCV3 Python API list
Python error list (Japanese)
List find in Python
Memorandum @ Python OR Seminar
Python exception class list
Initialize list with python
Extend python in C ++ (Boost.NumPy)
Python hand play (two-dimensional list)
Python list, for statement, dictionary
Summary of Python3 list operations
[Python] Convert list to Pandas [Pandas]
Python 3.4 or later standard pip
[Python] How to use list 1
Create ToDo List [Python Django]
Memorandum @ Python OR Seminar: matplotlib
Specify multiple list indexes (Python)
Python Basic Course (5 List Tuples)
Python list is not a list
Memorandum @ Python OR Seminar: Pulp
Python bitwise operator and OR
[Python] Copy of multidimensional list
[Introduction to Python] <list> [edit: 2020/02/22]
Python list and tuples and commas
Paiza Python Primer 4: List Basics
Memorandum @ Python OR Seminar: Pandas
Python list comprehensions and generators
[Python / PyQ] 4. list, for statement
Python #list for super beginners
Memorandum @ Python OR Seminar: scikit-learn
Ruby's `` like Python. 2.6 or later
Getting list elements in Python
Python or and and operator trap
Extract multiple list duplicates in Python
Difference between list () and [] in Python
[python] Manage functions in a list
Output 2017 Premium Friday list in Python
Python> list> append () and extend ()> append: list is added | extend: list elements are added | + = to add list
Python
Run mruby with Python or Blender
Which is better, PyPy or Python?
Convert list to DataFrame with python
[Python beginner] Divide one list (5 lines).
python / Make a dict from a list.
Python> list> Convert double list to single list
[Python] How to use list 3 Added