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