This article describes the Python tuple operation methods, shared for everyone to reference. The specific analysis is as follows:
In general, Python's functional usage is very flexible, and C, PHP usage is not the same, and JS is very similar.
When you follow the action, you can find a very magical phenomenon:
>>> T = (1, 3, ' B ')
>>> q = t + ((3, ' abc '))
>>> Q
(1, 3, ' B ', 3, ' abc ')
What I expected here was (1, 3, ' B ', (3, ' abc '), but it turns out to be (1, 3, ' B ', 3, ' abc '), and at first I guess Python is extracting all of the elements back together in the original order. Then I tried it again:
>>> q = t + ((3, ' abc '), ' 3 ')
>>> Q
(1, 3, ' B ', (3, ' abc '), ' 3 ')
Guess wrong, then why q = t + ((3, ' abc ') to split the tuple, I tried again:
>>> q = t + ((3, ' abc ', (' a '))
>>> Q
(1, 3, ' B ', 3, ' abc ', ' A ')
Python also removes the (' a ') from the tuple in the element, and in order to verify my thoughts, I test it further:
>>> q = t + ((3, ' abc ', (' A ', ' ab '))
>>> Q
(1, 3, ' B ', 3, ' abc ', (' A ', ' AB '))
It seems that the results are clear, in the case of A + operation on a tuple, Python will automatically parse the added tuple, and, in keeping with the primitive group structure, parse it into the simplest tuple to add, that is, to bracket the multiple tuples with only a single element.
So, if I don't want Python to get rid of it in the + operation, then that's fine:
>>> q = t + ((3, ' abc '),)
>>> Q
(1, 3, ' B ', (3, ' abc '))
I hope this article will help you with your study of Python programming.