How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python concatenate tuples operator with basic syntax and many examples for better understanding.
Python concatenate tuples (+) is used to add two tuples and create a new tuple value .
Syntax:
(tuple_variable_name1) + (tuple_variable_name2) + (tuple_variable_name3) + .......
Input Parameters:
- tuple_variable_name1 & tuple_variable_name2 : These are tuples that we want to be concatenated.
Example
versions=(0.1,0.2)
browsers=('crome','mozilla', 'ie')
# tuple after concatenation
newtuple=versions+browsers
print('New tuple:',newtuple)
Output
New tuple: (0.1, 0.2, ‘crome’, ‘mozilla’, ‘ie’)
In the above Example, by using concatenation operator (+), we have added two tuples ‘versions’ and ‘browsers ‘ as versions+browser in print statement, and created new tuple as (0.1, 0.2, ‘crome’, ‘mozilla’, ‘ie’).
Note: Concatenation operator implies that both the operands passed must be tuple else error will be shown.
In this tutorial, you have learned how to concatenate two tuples in python.
If you have an inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback.But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Similar Python operators:
- Repetition(‘*’) : It repeats element of tuple.
- Membership(‘in’ & ‘not in’) : It returns True , if given element is present in tuple otherwise returns False.
- tuple Iteration : It returns element of tuple by using for loop with tuple.
Python tutorials list:
- Python tutorials list : access all python tutorials.