`min()` 在 Python 中无法正常工作?

问题描述 投票:0回答:1

我是Python新手,在使用

min()
时注意到以下错误。

import pandas as pd
a = [1,2,3,4,5]
print(min(20, pd.array(a)**2))

代码应该返回[1, 4, 9, 16, 20],但是,它返回[1, 4, 9, 16, 25]。看来

min()
没有按预期工作。原因是什么以及如何解决?谢谢你。

python math min
1个回答
0
投票

你知道 5**2 = 25,对吧?或者我错过了理解它。您想要列表中所有小于 20 的数字,还是想用 20 替换最后一个数字?我这样认为是因为 min() 函数用于收集(例如)列表、数组等中的最小数字。

© www.soinside.com 2019 - 2024. All rights reserved.