Search code examples
pythonlistappendoperatorsextend

Is a Python list's += operator equivalent to append() or extend()?


Python lists have a += operator as well as append and extend methods.

If l is a list, is l += ... equivalent to l.append(...), l.extend(...), both, or neither?


Solution

  • In python += on a list is equivalent to extend method on that list.