Lecture-27 (Built-In Functions For List)
Lecture-27 (Built-In Functions For List)
LECTURE 27
Today’s Agenda
• List -III
These are:
len()
max()
min()
sum()
sorted()
list()
any()
all()
The len( ) Function
Output:
4
The max( ) Function
Example:
nums=[5,2,11,3]
print(max(nums))
Output:
11
Guess The Output ?
months=["january","may","december"]
print(max(months))
Output:
may
Guess The Output ?
booleans=[False,True]
print(max(booleans))
Output:
True
Guess The Output ?
mynums=[1.1,1.4,0.9]
print(max(mynums))
Output:
1.4
Guess The Output ?
mynums=[True,5,False]
print(max(mynums))
Output:
5
Guess The Output ?
mynums=[0.2,0.4,True,0.5]
print(max(mynums))
Output:
True
Guess The Output ?
mynums=["True",False]
print(max(mynums))
Output:
Guess The Output ?
values=[10,"hello",20,"bye"]
print(max(values))
Output:
Guess The Output ?
fruits=["apple","banana","orange"]
print(max(fruits))
Output:
Orange
Guess The Output ?
fruits=["apple","banana","orange",None]
print(max(fruits))
Output:
The min( ) Function
Example:
nums=[5,2,11,3]
print(min(nums))
Output:
2
Guess The Output ?
months=["january","may","december"]
print(min(months))
Output:
december
The sum( ) Function
Example:
nums=[10,20,30]
print(sum(nums))
Output:
60
Guess The Output ?
nums=[10,20,30,True,False]
print(sum(nums))
Output:
61
Guess The Output ?
nums=['1','2','3']
print(sum(nums))
Output:
Guess The Output ?
nums=[2.5,3.5,4.5]
print(sum(nums))
Output:
10.5
The sorted( ) Function
Example:
nums=[7,4,9,1]
print(sorted(nums))
print(nums)
Output:
Guess The Output ?
months=["january","may","december"]
print(sorted(months))
Output:
[“december”,”january”,”may”]
Guess The Output ?
months=["january","may","december",3]
print(sorted(months))
Output:
Guess The Output ?
values=[2.4,1.0,2,3.6]
print(sorted(values))
Output:
[1.0,2,2.4,3.6]
Guess The Output ?
values=["bhopal","bhop","Bhopal"]
print(sorted(values))
Output:
[“Bhopal”,”bhop”,”bhopal”]
Sorting In Descending Order
Example:
nums=[3,1,5,2]
print(sorted(nums,reverse=True))
Output:
The list( ) Function
Example:
city="bhopal"
x=list(city)
print(x)
Output:
Guess The Output ?
n=20
x=list(n)
print(x)
Output:
Guess The Output ?
n="20"
x=list(n)
print(x)
Output:
Guess The Output ?
t=(10,20,30)
x=list(t)
print(x)
This is a
Output: tuple
The any( ) Function
Example:
x = [1, 3, 4, 0]
print(any(x))
Output:
Guess The Output ?
x = [0, False]
print(any(x))
Output:
Guess The Output ?
x = [0, False, 5]
print(any(x))
Output:
Guess The Output ?
x= []
print(any(x))
Output:
The all( ) Function
Syntax:
list(iterable)
Example:
x = [1, 3, 4, 0]
print(all(x))
Output:
Guess The Output ?
x = [0, False]
print(all(x))
Output:
Guess The Output ?
x = [1,3,4,5]
print(all(x))
Output:
Guess The Output ?
x = [0, False, 5]
print(all(x))
Output:
Guess The Output ?
x= []
print(all(x))
Output: