Write A Python Script To Print The Docstring(Documentation String) Of The Input Function

Docstring / Documentation string is used to document the function, the details like function name, type of input arguments it takes, the data it processes and return values.

The documentation string is just like comment enclosed using triple quotes, and it will not be executed.

 

 

Write A Python Script To Print The Docstring(Documentation String) Of The Input Function

 

 


There are two ways to print doc string: first using magic method __doc__ and second is using help() function call.


Write A Python Script To Print The Docstring(Documentation String) Of The Input Function using __doc__

Just use the print function with input.__doc__ string, this will print out the doc string of input function call

Python Code
========================

print(input.__doc__)





Output
===============
Read a string from standard input.  The trailing newline is stripped.

The prompt string, if given, is printed to standard output without a
trailing newline before reading input.

If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.





Write A Python Script To Print The Docstring(Documentation String) Of The Input Function using help()

Use print function and pass input argument to help function to print the documentation string.
 

Python Code
========================

print(help(input))




Output
====================
Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.
    
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.




Output is just the function name that reads string from standard input until the next line is entered. Also you can specify the prompt as an argument to the user, prompt string is printed on standard output to display it to the user.


Conclusion
=======================
Try changing the input() function to some other function and note down the result.

Comment it down below if you have any suggestion to improve the above python program

Post a Comment

0 Comments