How to find the maximum and minimum value of a list in python

PHPz
Release: 2024-03-01 19:28:24
forward
1310 people have browsed it

How to find the maximum and minimum value of a list in python

You can use the built-in max() and min() functions to find the maximum and minimum values ​​of a list.

For example, suppose there is a list nums:

nums = [5, 2, 9, 1, 7]
Copy after login

To find the maximum value, you can use the max() function:

max_value = max(nums)
print(max_value)# Output: 9
Copy after login

To find the minimum value, you can use the min() function:

min_value = min(nums)
print(min_value)# Output: 1
Copy after login

This way you can find the maximum and minimum values ​​in the list.

The above is the detailed content of How to find the maximum and minimum value of a list in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:lsjlt.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template