gpt4 book ai didi

python-3.x - 属性错误 : 'module' object has no attribute 'div'

转载 作者:行者123 更新时间:2023-12-04 14:28:44 24 4
gpt4 key购买 nike

我尝试运行以下使用 python 3.2 的程序,出现错误:'module' object has no attribute 'div' 谁能告诉我我该怎么做才能解决这个问题?对此,我真的非常感激 !

import operator 
ops = {'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.div}

AttributeError: 'module' object has no attribute 'div

最佳答案

According to the docs ,在 Python 3 中有一个 truediv 和一个 floordiv。您需要使用其中之一。

operator.truediv(a, b) operator.__truediv__(a, b) Return a / b where 2/3 is .66 rather than 0. This is also known as “true” division.

operator.floordiv(a, b) operator.__floordiv__(a, b) Return a // b

关于python-3.x - 属性错误 : 'module' object has no attribute 'div' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485571/

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