Python anatomy

From wikinotes

python is pretty straightforwards.

Language Semantics

  • dynamically typed
  • 1st class objects

Best Practices

Python releases styleguides with best practices in the form of PEPs. (these are also used to propose changes to the python language). You can look them up here:


In particular PEP8 is the current style-guide used by the python project itself, and is used by most python projects:

Example Sourcefile

class MyClass(object):
    """ A docstring

    def print_stuff():
        """ Prints word 'stuff
        print('print stuff')

    def capitalize(text):
        """ Capitalizes and prints 'stuff'

            text (str):  text you'd like to capitalize
            str: Capitalized text.
        capitalized_text = text.upper()
        return capitalized_text

def hello_world():
    print('hello world')

# this code only runs if module is run directly
# (and not when imported)
if __name__ == '__main__':
    instance = MyClass()
    instance.capitalize('hi there')