我在 pycharm 和 jupyter notebook 中運行相同的代碼,它在 Pycharm 中運行但在 notebook 中運行時導致“TypeError: 'float' object is not callable”錯誤
lst = [-0.8952728022981113, -0.8256266449547354,
-0.18551647265920335, -0.7845995301231219,
0.8023977559033892, -0.9236926677953552,
0.07240408006785382, -0.3356046029806403,
0.7041732378587373, -0.6806752065560602,
-0.325566685781449, -0.33240721074208945]
MINIMUM_OF_SUBLIST = round(min(lst),3)
MAXIMUM_OF_SUBLIST = round(max(lst),3)
AVERAGE_OF_SUBLIST = round(sum(lst) / len(lst),3)
print(f"Minimum: {MINIMUM_OF_SUBLIST} / Maximum: {MAXIMUM_OF_SUBLIST} / Average: {AVERAGE_OF_SUBLIST}")
當我在 pycharm 中運行時,它輸出為最小值:-0.924 / 最大值:0.802 / 平均值:-0.309
但是在筆記本中運行時出現錯誤:-
TypeError Traceback (most recent call last)
<ipython-input-5-638bf02333bb> in <module>
6 -0.325566685781449, -0.33240721074208945]
7
----> 8 MINIMUM_OF_SUBLIST = round(min(lst),3)
9 MAXIMUM_OF_SUBLIST = round(max(lst),3)
10 AVERAGE_OF_SUBLIST = round(sum(lst) / len(lst),3)
TypeError: 'float' object is not callable
我不知道是什么問題(:
uj5u.com熱心網友回復:
似乎您min之前在筆記本中分配了一個值,就像現在float嘗試呼叫它時一樣。
min是 Python 中的保留關鍵字,因此您應該使用類似min_or 之類的東西min_val。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/314356.html
標籤:Python 蟒蛇-3.x 列表 jupyter-笔记本 谷歌合作实验室
下一篇:如何訪問號碼中的號碼
