Python Repeat Tuple
In this tutorial, we are going to explain how to use Python tuple repetition operator with basic syntax and many examples for better understanding.
How to repeat a tuple in Python? To repeat a tuple in Python, We use the asterisk operator ” * ” The asterisk. is used to repeat a tuple n (number) of times. Which is given by the integer value ” n ” and creates a new tuple value. It uses two parameters for an operation: the integer value and the other is a tuple.
Python Repeat Tuple Syntax:
<tuple_variable_name1> * N
N * <tuple_variable_name1>
Input Parameters:
- tuple_variable_name1 : The tuples that we want to be repeated.
- N : where is the number of times that we want that tuple to be repeated ex: 1,2,3,……..n
Python Repeat Tuple Example
data=(1,2,3,'a','b')
# tuple after repetition
print('New tuple:', data* 2)
Output
New tuple: [1, 2, 3, ‘a’, ‘b’, 1, 2, 3, ‘a’, ‘b’]
In the above Example, using repetition operator (*), we have repeated ‘data’ tuple variable 2 times by ‘data* 2’ in print statement and created new tuple as [1, 2, 3, ‘a’, ‘b’, 1, 2, 3, ‘a’, ‘b’].
In this tutorial, you have learned how to repeat a tuple in python n number of times.
Hopefully, it was clear and concise.
If you have a inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback as well.
Similar Python Operators:
- Concatenation(‘+’) : It adds two tuples.
- 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.
Related Articles
Python Tuples – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list : access all python tutorials.