python从键盘输入一个列表计算输出元素的平均值_python列表查找值_在Python中查找列表平均值的5种方法...

本文介绍了在Python中查找列表平均值的五种方法:使用mean()函数、内置sum()方法、lambda和reduce()方法、operator.add()方法以及NumPy的average()方法。每个方法都有详细的操作步骤和示例代码。
摘要由CSDN通过智能技术生成

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,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值