Tuple Concatenation :-
Python में Tuple Concatenation का अर्थ है दो या दो से अधिक Tuples को जोड़कर एक नया Tuple बनाना। Tuple Concatenation के लिए + operator का उपयोग किया जाता है।
English
Tuple Concatenation means joining two or more tuples together to create a new tuple. The + operator is used for tuple concatenation.
Syntax:-
tuple3 = tuple1 + tuple2
यहाँ tuple1 और tuple2 के सभी elements को क्रम से जोड़कर एक नया Tuple tuple3 में store किया जाता है।
Example:-
tuple1 = (10, 20, 30)
tuple2 = (40, 50, 60)
result = tuple1 + tuple2
print(result)
Output:-
(10, 20, 30, 40, 50, 60)
Because:-
यहाँ:
tuple1 → (10, 20, 30)
tuple2 → (40, 50, 60)
tuple1 + tuple2 → (10, 20, 30, 40, 50, 60)
+ operator ने दोनों Tuples के elements को same order में जोड़ दिया।
English
Here, the + operator joins all elements of tuple1 followed by all elements of tuple2 and creates a new tuple.
Concatenating Three Tuples :-
हम तीन या उससे अधिक Tuples को भी concatenate कर सकते हैं।
Example:-
tuple1 = (10, 20)
tuple2 = (30, 40)
tuple3 = (50, 60)
result = tuple1 + tuple2 + tuple3
print(result)
Output:-
(10, 20, 30, 40, 50, 60)
Because:-
तीनों Tuples के elements क्रम से एक नए Tuple में जुड़ गए।
Tuple Concatenation with Strings :-
String elements वाले Tuples को भी concatenate किया जा सकता है।
Example:-
names1 = ("Rahul", "Amit")
names2 = ("Neha", "Priya")
result = names1 + names2
print(result)
Output:-
('Rahul', 'Amit', 'Neha', 'Priya')
English
Tuples containing strings can also be concatenated using the + operator.
Concatenation with an Empty Tuple :-
Empty Tuple को किसी Tuple के साथ concatenate करने पर वही elements प्राप्त होते हैं।
numbers = (10, 20, 30)
empty = ()
result = numbers + empty
print(result)
Output:-
(10, 20, 30)
Tuple Concatenation Creates a New Tuple :-
Tuple Immutable होता है। इसलिए Concatenation original Tuples को modify नहीं करता। + operator एक नया Tuple बनाता है।
Example:-
tuple1 = (10, 20)
tuple2 = (30, 40)
result = tuple1 + tuple2
print(tuple1)
print(tuple2)
print(result)
Output:-
(10, 20)
(30, 40)
(10, 20, 30, 40)
English
Tuple concatenation does not modify the original tuples. It creates a new tuple.
Important Point :-
दोनों operands का Tuple होना आवश्यक है।
tuple1 = (10, 20)
tuple2 = (30, 40)
result = tuple1 + tuple2
यह valid है।
लेकिन:
tuple1 = (10, 20)
result = tuple1 + 30
यह TypeError देगा, क्योंकि 30 एक Tuple नहीं है।