Why wasn't the line printed at the top of this function?

In the tutorial, I found the following function. When I call the function, it "This prints a passed string into this function"does not print. Why does the function not print this part of the text when called?

def printme(str):
   "This prints a passed string into this function"
   print str
   return

# Now you can call printme function
printme("I'm first call to user defined function!")
printme("Again second call to the same function")
+4
source share
2 answers

What you see is a document line or a short line.

A docstring is a string that should document the subject to which it is bound. In your case, it is bound to a function, and as such it is supposed to document the function. You can also have docstrings for classes and modules.

docstrings, , ( ). docstring __doc__:

>>> def printme( str ):
        "This prints a passed string into this function"
        print str

>>> printme.__doc__
'This prints a passed string into this function'

help():

>>> help(printme)
Help on function printme in module __main__:

printme(str)
    This prints a passed string into this function

docstrings, , docstrings, "" , . , , , :

def printme (str):
    '''
    Print the string passed in the `str` argument to the
    standard output. This is essentially just a wrapper
    around Python’s built-in `print`.
    '''
    print(str)

docstring PEP 257.

+10

, no-op. , REPL, - REPL - RE P L, read eval print. .

+5

Source: https://habr.com/ru/post/1611842/


All Articles