Repository navigation
Expand file tree
/
Copy path068-Repeat-Tuple.py
More file actions
86 lines (69 loc) · 3.08 KB
/
Copy path068-Repeat-Tuple.py
File metadata and controls
86 lines (69 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
===============================================================================
File Name : 68-Repeat-Tuple.py
Description : Repeat a Tuple in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
Tuple repetition is the process of repeating the elements of a tuple multiple
times using the (*) operator.
Syntax:
new_tuple = tuple_name * number
Example:
numbers = (10, 20)
result = numbers * 3
"""
# -----------------------------------------------------------------------------
# Creating a tuple of integers.
# -----------------------------------------------------------------------------
numbers = (10, 20, 30)
# -----------------------------------------------------------------------------
# Displaying the original tuple.
# -----------------------------------------------------------------------------
print("Original Tuple :", numbers)
# Output:
# Original Tuple : (10, 20, 30)
print()
# -----------------------------------------------------------------------------
# Repeating the tuple two times.
# -----------------------------------------------------------------------------
repeated_twice = numbers * 2
# -----------------------------------------------------------------------------
# Displaying the repeated tuple.
# -----------------------------------------------------------------------------
print("Tuple Repeated 2 Times :", repeated_twice)
# Output:
# Tuple Repeated 2 Times : (10, 20, 30, 10, 20, 30)
print()
# -----------------------------------------------------------------------------
# Repeating the tuple three times.
# -----------------------------------------------------------------------------
repeated_thrice = numbers * 3
# -----------------------------------------------------------------------------
# Displaying the repeated tuple.
# -----------------------------------------------------------------------------
print("Tuple Repeated 3 Times :", repeated_thrice)
# Output:
# Tuple Repeated 3 Times : (10, 20, 30, 10, 20, 30, 10, 20, 30)
print()
# -----------------------------------------------------------------------------
# Creating a tuple of strings.
# -----------------------------------------------------------------------------
fruits = ("Apple", "Banana")
# -----------------------------------------------------------------------------
# Repeating the string tuple.
# -----------------------------------------------------------------------------
repeated_fruits = fruits * 2
# -----------------------------------------------------------------------------
# Displaying the repeated string tuple.
# -----------------------------------------------------------------------------
print("Repeated Fruit Tuple :", repeated_fruits)
# Output:
# Repeated Fruit Tuple : ('Apple', 'Banana', 'Apple', 'Banana')
print()
# -----------------------------------------------------------------------------
# Displaying the total number of elements in the repeated tuple.
# -----------------------------------------------------------------------------
print("Total Elements :", len(repeated_thrice))
# Output:
# Total Elements : 9