gpt4 book ai didi

python - 错误消息: "int object is not callable" when trying to make a double comprehension list

转载 作者:行者123 更新时间:2023-12-01 00:33:33 26 4
gpt4 key购买 nike

我正在尝试制作一个看起来像 [1^1, 2^1, 3^1, 1^2, 2^2, 3^2, 1^3, 2^3 的双重理解列表, 3^3] 直到指数达到 99

very_long_list=[f(i) for i in range(1,99) for f in [1,2,3]]

这告诉我 int 不可调用,我不知道这意味着什么......

最佳答案

您应该将 f(i) 替换为幂运算符,即 f**i:

very_long_list = [f**i for i in range(1, 99) for f in [1,2,3]]

这将导致:

[1, 2, 3, 1, 4, 9, 1, 8, 27, 1, 16, 81, 1, 32, 243, 1, 64, ...

关于python - 错误消息: "int object is not callable" when trying to make a double comprehension list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57985414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com