Important Notice:

Common Tuple Operations

Common Tuple Operations

8 views 2 min read
Common Tuple Operations :-
Python में Common Tuple Operations का अर्थ है वे सामान्य operations जो Tuple के elements पर perform किए जा सकते हैं। इन operations की सहायता से हम Tuple को access, combine, repeat, search और analyze कर सकते हैं।

English

Common Tuple Operations are the common operations that can be performed on tuple elements. These operations are used to access, combine, repeat, search, and analyze tuples.

1. Accessing Elements :-

Tuple के elements को index number की सहायता से access किया जा सकता है।

Example:-

numbers = (10, 20, 30, 40)

print(numbers[1])

Output:-

20

English:
Tuple elements can be accessed using their index numbers.

2. Indexing :-

Tuple में indexing 0 से शुरू होती है।

numbers = (10, 20, 30, 40)

print(numbers[0])
print(numbers[3])

Output:-

10
40
 
3. Negative Indexing :-

Tuple के elements को end से access करने के लिए negative indexing का उपयोग किया जाता है।

numbers = (10, 20, 30, 40)

print(numbers[-1])
print(numbers[-2])

Output:-

40
30
 
4. Slicing :-

Tuple के एक से अधिक elements को access करने के लिए slicing का उपयोग किया जाता है।

numbers = (10, 20, 30, 40, 50)

print(numbers[1:4])

Output:-

(20, 30, 40)

English:
Slicing is used to access a range of elements from a tuple.

5. Concatenation :-

दो या अधिक Tuples को जोड़ने के लिए + operator का उपयोग किया जाता है।

tuple1 = (10, 20)
tuple2 = (30, 40)

print(tuple1 + tuple2)

Output:-

(10, 20, 30, 40)
 
6. Repetition :-

Tuple के elements को multiple times repeat करने के लिए * operator का उपयोग किया जाता है।

numbers = (10, 20)

print(numbers * 3)

Output:-

(10, 20, 10, 20, 10, 20)
 
7. Membership Testing :-

यह check करने के लिए कि कोई element Tuple में मौजूद है या नहीं, in और not in operators का उपयोग किया जाता है।

numbers = (10, 20, 30, 40)

print(20 in numbers)
print(50 not in numbers)

Output:-

True
True

English:
The in and not in operators are used to check whether an element exists in a tuple.

8. Finding Length :-

Tuple में total elements की संख्या जानने के लिए len() function का उपयोग किया जाता है।

numbers = (10, 20, 30, 40, 50)

print(len(numbers))

Output:-

5
 
9. Finding Maximum and Minimum :-

Numeric Tuple में सबसे बड़ी और सबसे छोटी value प्राप्त करने के लिए max() और min() functions का उपयोग किया जाता है।

numbers = (10, 50, 20, 80, 30)

print(max(numbers))
print(min(numbers))

Output:-

80
10
 
10. Finding Sum :-

Tuple के numeric elements का total निकालने के लिए sum() function का उपयोग किया जाता है।

numbers = (10, 20, 30, 40)

print(sum(numbers))

Output:-

100
 
11. Counting Elements :-

किसी particular value के Tuple में कितनी बार आने की संख्या जानने के लिए count() method का उपयोग किया जाता है।

numbers = (10, 20, 10, 30, 10)

print(numbers.count(10))

Output:-

3

English:
The count() method returns the number of times a specified value occurs in a tuple.

12. Finding Position of an Element :-

किसी element का पहला index पता करने के लिए index() method का उपयोग किया जाता है।

numbers = (10, 20, 30, 40)

print(numbers.index(30))

Output:-

2

 

Related Notes