Built-in Functions with Tuples :-
Python में कई Built-in Functions उपलब्ध हैं जिनका उपयोग Tuple के elements पर अलग-अलग operations करने के लिए किया जाता है। इन functions की सहायता से हम Tuple की length, maximum value, minimum value, total sum और अन्य information प्राप्त कर सकते हैं।
English
Python provides several Built-in Functions that can be used with Tuples to perform different operations. These functions help us find the length, maximum value, minimum value, total sum, and other information from a tuple.
1. len() Function :-
len() function Tuple में मौजूद total number of elements बताता है।
Example:-
numbers = (10, 20, 30, 40, 50)
print(len(numbers))
Output:-
5
Because:-
Tuple में कुल 5 elements हैं, इसलिए len(numbers) का result 5 होगा।
English
The len() function returns the total number of elements in a tuple.
2. max() Function :-
max() function Tuple में मौजूद सबसे बड़ी value return करता है।
Example:-
numbers = (10, 50, 20, 80, 30)
print(max(numbers))
Output:-
80
English
The max() function returns the largest element in a tuple.
3. min() Function :-
min() function Tuple में मौजूद सबसे छोटी value return करता है।
Example:-
numbers = (10, 50, 20, 80, 30)
print(min(numbers))
Output:-
10
English
The min() function returns the smallest element in a tuple.
4. sum() Function :-
sum() function Tuple के numeric elements का total निकालता है।
Example:-
numbers = (10, 20, 30, 40)
print(sum(numbers))
Output:-
100
English
The sum() function returns the total of the numeric elements in a tuple.
5. sorted() Function :-
sorted() function Tuple के elements को sorted order में arrange करके एक नई List return करता है।
Example:-
numbers = (40, 10, 30, 20)
result = sorted(numbers)
print(result)
Output:-
[10, 20, 30, 40]
Important: sorted() Tuple को modify नहीं करता और इसका result List होता है।
English
The sorted() function returns a new list containing the tuple elements in sorted order.
6. any() Function :-
any() function True return करता है यदि Tuple में कम से कम एक element truthy हो।
Example:-
values = (False, False, True)
print(any(values))
Output:-
True
English
The any() function returns True if at least one element in the tuple is truthy.
7. all() Function :-
all() function True return करता है यदि Tuple के सभी elements truthy हों।
Example:-
values = (True, True, True)
print(all(values))
Output:-
True
यदि कोई element False हो:
values = (True, False, True)
print(all(values))
Output:-
False
English
The all() function returns True only when all elements in the tuple are truthy.
8. tuple() Function :-
tuple() function का उपयोग किसी iterable को Tuple में convert करने के लिए किया जाता है।
Example:-
numbers = tuple([10, 20, 30])
print(numbers)
Output:-
(10, 20, 30)
String को Tuple में convert करना:
letters = tuple("ABC")
print(letters)
Output:-
('A', 'B', 'C')
English
The tuple() function creates a tuple from an iterable object.
Important Built-in Functions with Tuples :-
len() → Tuple में elements की संख्या बताता है।
max() → सबसे बड़ी value return करता है।
min() → सबसे छोटी value return करता है।
sum() → Numeric elements का total निकालता है।
sorted() → Sorted elements की नई List return करता है।
any() → कम से कम एक truthy element होने पर True देता है।
all() → सभी elements truthy होने पर True देता है।
tuple() → Iterable को Tuple में convert करता है।