How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python list repetition operator with basic syntax and many examples for better understanding.
Python list repetition operator (*) is used to repeat a list, number of times which is given by the integer value and create a new list values.
Syntax:
(list_variable_name1) * N
N * (list_variable_name1)
Input Parameters:
- list_variable_name1 : The lists that we want to be repeated.
- N : where is the number of times that we want that list to be repeated ex: 1,2,3,……..n
Example
data=[1,2,3,'a','b']
# list after repetition
print('New list:', data* 2)
Output
New list: [1, 2, 3, ‘a’, ‘b’, 1, 2, 3, ‘a’, ‘b’]
In the above Example, using repetition operator (*), we have repeated ‘data’ list variable 2 times by ‘data* 2’ in print statement and created new list as [1, 2, 3, ‘a’, ‘b’, 1, 2, 3, ‘a’, ‘b’].
In this tutorial, you have learned how to repeat a lists 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:
- Concatenation(‘+’) : It adds two lists.
- Membership(‘in’ & ‘not in’) : It returns True , if given element is present in list otherwise returns False.
- List Iteration : It returns element of list by using for loop with list.
Python tutorials list:
- Python tutorials list : access all python tutorials.