Python Repetition in Tuples and N Times Repeating
Python repetition in tuples and N times repeating.
We can repeat the elements in a tuple for a given number of times using the
my_tuple = ('shouts',) * 3 print(my_tuple)
('shouts', 'shouts', 'shouts')
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)
The tuple is : shouts The tuple after repeating 3 times is: ('shouts', 'shouts', 'shouts')
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.