python AttributeError:模块“math”没有属性“comb”

Kri*_*chu 4 math python-3.7 comb

当我尝试使用“comb”功能时出现错误:

$ python
Python 3.7.1 (default, Dec 14 2018, 13:28:58) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> print(math.comb(6,49))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'math' has no attribute 'comb'
>>> 
Run Code Online (Sandbox Code Playgroud)

小智 5

Comb 函数是 Python 3.8 中的新增函数(请参阅此处的文档)。您的 Python 安装版本是 3.7.1。如果您更新 Python 安装,该问题应该可以解决。