python function Tips

In some scripts we write when we must add a comment, or a long time could not remember his own time code is what to do with the, in python, we will do some descriptions of some functions, but sometimes do not open the code can not see the explanation of each function, python provides a very convenient tool docstrings (documentation strings) document character, it can easily print out the description of the function, I wrote a small example.

#-*-coding:utf-8-*-
#author:yangdong
def print_documentation(x,y):
    '''this is a function to learn how to make __doc__
    to print the documentation!!
    the function's result is the max number'''
    x=int(x)
    y=int(y)
    if x > y:
        return x
    elif x == y:
        return  "the tow number is equal!"
    else:
        return y

print(print_documentation(4,6))
print(print_documentation.__doc__)

operation result:

6
this is a function to learn how to make __doc__
    to print the documentation!!
    the function's result is the max number

 

Guess you like

Origin www.cnblogs.com/yangxiaochu/p/11238162.html