python列表查找值
Hi Folks! In this article, we will have a look at the various ways to find the average of a list in a Python List.
嗨伙计! 在本文中,我们将介绍在Python List中查找列表平均值的各种方法 。
In general, an average is a value that represents a whole set of data items or elements.
通常,平均值是代表整个数据项或元素集的值。
Formula: Average = summation of numbers/total count.
公式:平均值=数字总和/总计数。
在Python中查找列表平均值的技巧 (Techniques to find the average of a list in Python)
Either of the following techniques can be used to calculate the average/mean of a list in Python:
以下任何一种技术均可用于计算Python中列表的平均值/均值:
Python mean() function
Python mean()函数
In-built sum() method
内置sum()方法
Python lambda and reduce() method
Python Lambda和reduce()方法
Python operator.add() method
Python operator.add()方法
1. Python mean()函数 (1. Python mean() function)
Python 3 has statistics module which contains an in-built function to calculate the mean or average of numbers. The statistics.mean() function is used to calculate the mean/average of input values or data set.
Python 3具有statistics module ,该statistics module包含一个内置函数来计算数字的均值或平均值。 statistics.mean() function用于计算输入值或数据集的平均值/平均值 。
The mean() function accepts the list, tuple or data-set containing numeric values as a parameter and returns the average of the data-items.
mean()函数接受包含数值的列表,元组或数据集作为参数,并返回数据项的平均值。
Syntax:
句法:
mean(data-set/input-values)
Example:
例:
from statistics import mean
inp_lst = [12, 45, 78, 36, 45,