__add__ is internal implementation that is called by + operator (i.e. concatenation)
https://docs.python.org/3/library/stdtyp...l#typesseq
read carefully note 6 and 3rd item in the bullet list
apart from performance issue that is discussed, note that concatenating tuple is equivalent of extending a list, but extending the list has better performance
https://docs.python.org/3/library/stdtyp...l#typesseq
read carefully note 6 and 3rd item in the bullet list
Quote:Concatenating immutable sequences always results in a new object. This means that building up a sequence by repeated concatenation will have a quadratic runtime cost in the total sequence length. To get a linear runtime cost, you must switch to one of the alternatives below:
if concatenating str objects, you can build a list and use str.join() at the end or else write to an io.StringIO instance and retrieve its value when complete
if concatenating bytes objects, you can similarly use bytes.join() or io.BytesIO, or you can do in-place concatenation with a bytearray object. bytearray objects are mutable and have an efficient overallocation mechanism
if concatenating tuple objects, extend a list instead
for other types, investigate the relevant class documentation
apart from performance issue that is discussed, note that concatenating tuple is equivalent of extending a list, but extending the list has better performance