Python> function> Docstrings> Description to display with help () / .__ doc__

Operating environment


CentOS release 6.8 (Final)
Python 2.6.6

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2599 / 12833)

Something called Docstrings was introduced. I've tried.

test_170331a.py


def my_echo(anything):
	'''
	prints [anything]
	with an air of reserve
	does not take [anything] seriously
	'''
	print("(in a small voice)"),
	print("...")
	print(anything)
	print("...")
	return

help(my_echo)

Run


$ python test_170331a.py
Help on function my_echo in module __main__:

my_echo(anything)
    prints [anything]
    with an air of reserve
    does not take [anything] seriously

reference

Docstrings related conventions https://www.python.org/dev/peps/pep-0257/

__doc__

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2628 / 12833)

An example of using __doc__ is introduced. I've tried.

test_170331b.py


def my_echo(anything):
	'''
	prints [anything]
	with an air of reserve
	does not take [anything] seriously
	'''
	print("(in a small voice)"),
	print("...")
	print(anything)
	print("...")
	return

#help(my_echo)
print(my_echo.__doc__)

result


$ python test_170331b.py 

	prints [anything]
	with an air of reserve
	does not take [anything] seriously

Recommended Posts

Python> function> Docstrings> Description to display with help () / .__ doc__
How to display python Japanese with lolipop
How to add help to HDA (with Python script bonus)
[Introduction to Python] How to iterate with the range function?
It's too troublesome to display Japanese with Vim's python3.
Site notes to help you use NetworkX with Python
Connect to BigQuery with Python
Connect to Wikipedia with Python
Post to slack with Python 3
Switch python to 2.7 with alternatives
Write to csv with Python
Create a Mastodon bot with a function to automatically reply with Python
[Introduction to Python] How to get data with the listdir function
Python: How to use async with
Link to get started with python
[Road to Python Intermediate] Call a class instance like a function with __call__
[Python] Write to csv file with Python
[Introduction to Python] How to split a character string with the split function
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
[Python 3.8 ~] How to define a recursive function smartly with a lambda expression
Output to csv file with Python
Linking Python and Arduino to display IME On / Off with LED
Convert list to DataFrame with python
MP3 to WAV conversion with Python
To do tail recursion with Python2
What to do with PYTHON release?
Unable to install Python with pyenv
[Python] Explains how to use the format function with an example
Try to display google map and geospatial information authority map with python
How to use FTP with Python
How to calculate date with python
How to use python zip function
Easily post to twitter with Python 3
How to display legend marks in one with Python 2D plot
I tried to make an image similarity function with Python + OpenCV
[Python] Explains how to use the range function with a concrete example
[Introduction to Python] How to write a character string with the format function
[Python] Calendar-style heat map (with holiday display)
Calculate and display standard weight with python
Create a Python function decorator with Class
Try logging in to qiita with Python
Change Python 64bit environment to 32bit environment with Anaconda
English speech recognition with python [speech to text]
Convert memo at once with Python 2to3
HTML email with image to send with python
[Python] How to display random numbers (random module)
Memo to ask for KPI with python
Python to remember only with hello, worlds
Output color characters to pretty with python
How to write Python document comments (Docstrings)
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
Display Python 3 in the browser with MAMP
Convert Excel data to JSON with python
[python] How to use __command__, function explanation
Convert Hiragana to Romaji with Python (Beta)
Fractal to make and play with Python
I wanted to solve ABC160 with Python
Connect to MySQL with Python within Docker
[Introduction to Udemy Python3 + Application] 45. enumerate function