User Tools

Site Tools


wiki:template

A template for writing Python code

template.py
"""
Template for how a python module shold look like.
 
Author:  Asa Ben-Hur
 
All the stuff in triple quotes is called a docstring, and its
objective is to document the module/function in which it occurs
For details:
https://docs.python.org/3.1/tutorial/controlflow.html#documentation-strings
"""
 
def double(x) :
    """
    doubles the value that is provided as input.
    works for any Python type that support the * operator
    """
    return 2 * x
 
if __name__ == '__main__' :
    """
    This segment of the program is used for testing the code you have
    created.  It is automatically executed when you run the file as a script.
    See:
    https://docs.python.org/3/library/__main__.html
    And a more in-depth explanation with examples at:
    http://www.bogotobogo.com/python/python_if__name__equals__main__.php
    """
    print ("10 * 2 = ", double(10))
    print ("Python * 2 = ", double("Python"))
 
wiki/template.txt ยท Last modified: 2016/09/01 09:29 (external edit)