Learn Python by Building Data Science Applications
上QQ阅读APP看书,第一时间看更新

The max, min, and sum functions

The max, min, and sum functions all take an array of numbers and return the maximum, minimum, or sum value as a result. Here are some examples:

>>> T = 1,2,3
>>> min(T)
1
>>> max(T)
3
>>> sum(T)
6

As you can see, a tuple can be assigned to a variable without any brackets. All three results are expected—of values 1, 2, and 31 is the minimum, 3 is the maximum, and the sum of those three values is equal to 6.

So now that we know what a function is and its properties, let's see how we can define them and why defining is important.