all Python 3operatorfunction
operator.iconcat
in-place
In-place concatenation: a += b for sequences.
Syntax
operator.iconcat(a, b)
The first argument must be a sequence or TypeError is raised, but when it is a list the second can be any iterable: iconcat([1], (2,)) gives [1, 2]. For a list it is the same as list.extend, with the same effect on other references. For strings and tuples assign the result — they are immutable.
Examples
import operator
print(operator.iconcat([1], [2])) # → [1, 2]
nums = [1, 2]
print(operator.iconcat(nums, [3, 4]) is nums) # → True
print(nums) # → [1, 2, 3, 4]
print(operator.iconcat('ab', 'cd')) # → abcd
print(operator.iconcat([1], 2)) # → TypeError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy