Python Repetition in Tuples and N Times Repeating

Python repetition in tuples and N times repeating.

Repetition in Tuples

We can repeat the elements in a tuple for a given number of times using the * operator:

my_tuple = ('shouts',) * 3
print(my_tuple)

Output:

('shouts', 'shouts', 'shouts')
N Times Repeating

my_tuple = ('shouts')

print("The tuple is : " + str(my_tuple))

n = 3

my_result = ((my_tuple,) * n)

print("The tuple after repeating " + str(n) + " times is:")
print(my_result)

Output:

The tuple is : shouts
The tuple after repeating 3 times is:
('shouts', 'shouts', 'shouts')