为什么其他注释不能显示出来呢?
来源:2-6 模块的属性
慕粉1523819
2020-03-19 13:54:17
>> import hello
>>> dir(hello)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__sp
ec__', 'add', 'fun']
>>> hello.__add__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'hello' has no attribute '__add__'
>>>
1回答
同学,你好。因为__add__不是hello中的方法或属性,所以调用会报错。要显示文档说明可以用__doc__方法,如hello.__doc__,__doc__是hello模块的内置方法,用来显示模块的说明文档的,要想显示模块下的函数说明文档,可以用help,如help(add),来显示方法add的说明内容。
如果解决了你的疑惑,请采纳,祝学习愉快~
相似问题
回答 1
回答 1