Home  >  Article  >  Backend Development  >  How to find the maximum value of a set of numbers in python?

How to find the maximum value of a set of numbers in python?

coldplay.xixi
coldplay.xixiOriginal
2020-06-23 10:31:5316154browse

How to find the maximum value of a set of numbers in python?

#How to find the maximum value of a set of numbers in python?

Python method to find the maximum value of a set of numbers:

First define a set of numbers and variable a, and assign [a=list(0)] ; Then use range loop to query. If the number is greater than [list=(0)], then pass the value to a and output it.

def max2(list):
    a = list[0]
    for prime in range (1,len(list)):
        if list[prime] > list[0]:
         a = list[prime]
    return a
print(max2([1,5,2,3,6,8,10,15]))

Recommended tutorial: "python video tutorial"

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

Statement:
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