Calculating Minimum, Maximum, and Sum
The min
, max
, and sum
functions calculate the minimum value
, maximum value
, and total sum
for iterable objects such as lists and tuples.
min() Function
The min
function returns the smallest value within a list or tuple.
Example of min Function
numbers = [4, 2, 8, 6]
min_element = min(numbers)
print(min_element) # 2
max() Function
The max
function returns the largest value within a list or tuple.
Example of max Function
numbers = (4, 2, 8, 6)
max_element = max(numbers)
print(max_element) # 8
sum() Function
The sum
function returns the total sum of all numbers within a list or tuple.
Example of sum Function
numbers = [4, 2, 8, 6]
sum_of_numbers = sum(numbers)
print(sum_of_numbers) # 20
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.