Python Join Tuples
Joining tuples means combining two or more tuples into a single tuple. Since tuples are immutable, joining creates a new tuple. This is useful when you want to merge data collections or extend existing tuples without modifying the originals.
Tuples को जोड़ने का मतलब होता है दो या अधिक tuples को मिलाकर एक नया tuple बनाना। क्योंकि tuples immutable होते हैं, इसलिए जोड़ने पर एक नया tuple बनता है। यह तब उपयोगी होता है जब आप अलग-अलग डेटा collections को merge करना चाहते हैं या मौजूदा tuples को बिना बदले बढ़ाना चाहते हैं।
Why join tuples?
- To combine multiple tuples into one.
- To create new data sets from existing tuples.
- To extend tuple data without modifying the original.
- When you want to concatenate sequences efficiently.
- कई tuples को एक में जोड़ने के लिए।
- मौजूदा tuples से नया data set बनाने के लिए।
- मूल tuple को बदले बिना डेटा बढ़ाने के लिए।
- Sequences को जल्दी और efficiently जोड़ने के लिए।
Example 1: Using + Operator to Join Tuples
t1 = (1, 2, 3)
t2 = (4, 5, 6)
joined = t1 + t2
print(joined)
Use + operator to concatenate two tuples.
+ operator से दो tuples को जोड़ें।
Output:
Example 2: Joining Multiple Tuples
t1 = ('a', 'b')
t2 = ('c', 'd')
t3 = ('e', 'f')
joined = t1 + t2 + t3
print(joined)
Join more than two tuples by chaining + operator.
+ operator से तीन या अधिक tuples जोड़ें।
Output:
Example 3: Join Tuple with Single Element Tuple
t1 = (1, 2)
t2 = (3,)
joined = t1 + t2
print(joined)
Join tuple with a single-element tuple (note the comma).
एक element वाले tuple के साथ जोड़ें (comma जरूरी)।
Output:
Example 4: Using * Operator with Tuples
t = (1, 2)
joined = t * 3
print(joined)
Repeat the tuple elements multiple times using * operator.
* operator से tuple को कई बार दोहराएं।
Output:
Example 5: Convert Tuple to List to Join and Back
t1 = (1, 2)
t2 = (3, 4)
list_joined = list(t1) + list(t2)
tuple_joined = tuple(list_joined)
print(tuple_joined)
Convert tuples to lists, join lists, then convert back to tuple.
Tuple को list में बदलकर जोड़ें फिर वापस tuple बनाएं।
Output: