def printMax(x,y):'''Prints the maximum of two numbers.The two values must be integers.'''x=int(x)y=int(y)if x>y:print(x,'is maximum')else:print(y,'is maximum')printMax(3,5)print (printMax._doc_) 代码如上,然而执行结果如下>>> 5 is maximumT
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/24 20:56:07
def printMax(x,y):'''Prints the maximum of two numbers.The two values must be integers.'''x=int(x)y=int(y)if x>y:print(x,'is maximum')else:print(y,'is maximum')printMax(3,5)print (printMax._doc_) 代码如上,然而执行结果如下>>> 5 is maximumT
def printMax(x,y):
'''Prints the maximum of two numbers.
The two values must be integers.'''
x=int(x)
y=int(y)
if x>y:
print(x,'is maximum')
else:
print(y,'is maximum')
printMax(3,5)
print (printMax._doc_)
代码如上,然而执行结果如下
>>>
5 is maximum
Traceback (most recent call last):
File "D:/Python31/code/func_doc.py",line 16,in
print (printMax._doc_) #printMax._doc_需放在字符串中
AttributeError:'function' object has no attribute '_doc_'
>>>
def printMax(x,y):'''Prints the maximum of two numbers.The two values must be integers.'''x=int(x)y=int(y)if x>y:print(x,'is maximum')else:print(y,'is maximum')printMax(3,5)print (printMax._doc_) 代码如上,然而执行结果如下>>> 5 is maximumT
print (printMax._doc_)
关键是这句话,你调用了自定义函数的一个方法,但是这个方法你没有定义所以才会报错.估计你是想调用函数自带的说明文档方法.那么你应该这么写:print (printMax.__doc__).注意doc左右的下划线,你两边分别写了1个,应该分别写2个