How To Write Good Python Functions. In python, like most modern programming languages, the function is a primary method of abstraction and encapsulation. Sum += arg return sum.

Each component can have only one docstring. The general syntax for creating a function in python looks something like this: Finally, if you want to learn how to write good python code or pythonic code, all you need to do is follow the zen of python.