Average of list in PythonIn this tutorial, we will discuss how we can compute the average of the list in Python. The average of a list is defined as the sum of elements present in the list divided by the number of elements present in the list. Here, we will make use of three different approaches to calculate the average of the elements present in the list using Python.
So, let’s get started… Using sum()In the first method, we have used the sum() and len() to calculate the average. The following program illustrates the same- Output: The average of the list is 34.5 Explanation- It’s time to have a look at what we have done in the above program-
In the next program, we will see how reduce() can help us to do the same. Using reduce()The program given below shows how it can be done- Output: The average of the list is 34.5 Explanation Let’s understand what we have done here-
In the last program, we will learn how mean() can be used to calculate the average of list Using mean()The following program shows how it can be done- Output: The average of the list is 34.5 Explanation- It’s time to have a look at what we have done in the above program-
ConclusionIn this tutorial, we learned the different methods of calculating the average of elements present in the list using Python. |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263392.html