- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Repeating tuples N times in Python
When it is required to repeat a tuple 'N' times, the '*' operator can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.
The '*' operator behaves like a multiplication operator.
Below is a demonstration of the same −
my_tuple_1 = (11, 14, 0) print("The tuple is : ") print(my_tuple_1) N = 5 my_result = ((my_tuple_1, ) * N) print("The tuple after duplicating "+ str(N) + " times is") print(my_result)
The tuple is : (11, 14, 0) The tuple after duplicating 5 times is ((11, 14, 0), (11, 14, 0), (11, 14, 0), (11, 14, 0), (11, 14, 0))
- A tuple is defined, and is displayed on the console.
- The value of 'N' is defined.
- This tuple is multiplied by 'N'.
- This is assigned to a value.
- It is displayed on the console.
- N element incremental tuples in Python
- Chunk Tuples to N in Python
- Calculate n + nn + nnn + ? + n(m times) in Python
- Trim tuples by N elements in Python
- Remove tuples from list of tuples if greater than n in Python
- Calculate n + nn + nnn + … + n(m times) in Python program
- Calculate n + nn + nnn + u + n(m times) in Python Program
- Python Program to calculate n+nm+nmm.......+n(m times).
- Program to rotate a string of size n, n times to left in Python
- Python - Check if k occurs atleast n times in a list
- Combining tuples in list of tuples in Python
- Updating Tuples in Python
- Compare tuples in Python