Getting a Coding Job: Python Design Principles and Code - dummies

Getting a Coding Job: Python Design Principles and Code

By Nikhil Abraham

You should know some things about Python if you are seeking a coding job. Python was created by Guido van Rossum, a developer who was bored during the winter of 1989 and looking for a project to do. Van Rossum had helped create one language, ABC, and the experience had given him many ideas that he thought would appeal to programmers. He executed these ideas when he created Python.

Although ABC never achieved popularity with programmers, Python was a runaway success. Python is one of the world’s most popular programming languages, used by those just starting out as well as professionals building heavy‐duty applications.

The Zen of Python, a poem that is part of the Python documentation, contains nineteen design principles that describe how the Python language is organized. Some of the most important principles include the following:

  • Readability counts: This is possibly Python’s most important design principle. Python code looks similar to English and even enforces certain formatting, such as indenting, to make the code easier to read. With highly readable code, you’ll find it much easier to fix a bug or add a feature months later. Readable code also means others can use your code or help debug your code with ease. is one of the top 10 most visited websites in the US, and one of the top 50 most visited websites in the world. Its cofounder, Steve Huffman, initially coded the website in Lisp but switched to Python because it is “extremely readable, and extremely writeable.”

  • There should be one — and preferably only one — obvious way to do it: This principle is directly opposite Perl’s motto, “There’s more than one way to do it.” In Python, two programmers may approach the same problem and write two different programs, but the ideal is that the code will be similar and easy to read, adopt, and understand. Although Python may allow you to perform a task in multiple ways, you should use the most obvious and common option.

  • If the implementation is hard to explain, it’s a bad idea: Programmers have been known to write esoteric code to increase performance. However, Python was designed to be easy to use, and this principle reminds programmers that easy‐to‐understand implementations are preferable over faster but harder‐to‐explain ones.

Access the full list of design principles, which is in the form of a poem, by typing import this; in any Python interpreter, or by visiting These principles, written by Python community member Tim Peters, describe the intentions of Python’s creator, Van Rossum, who is also referred to as the Benevolent Dictator for Life (BDFL).

Python generally uses less punctuation than other programming languages you may have previously tried. Some sample code is included here:

first_name=raw_input(“What’s your first name?”)
if first_name==“NIK”:
 print “You may enter!”
 print “Nothing to see here.”

Two popular versions of Python are currently in use: Python 2.7 and Python 3. Python 3 is the latest version of the language but it is not backwards compatible, so code written using Python 2.7 syntax does not work when using a Python 3 interpreter. Initially, Python 2.7 had more external libraries and support than Python 3, but this is changing. Check here for more about the differences between the two Python versions.

If you ran this code, it would do the following:

  1. Print a line asking for your first name.

  2. Take the user input (raw_input(Whats your first name?)) and save it to the first_name variable.

  3. Transform any inputted text into uppercase.

    Test the user input. If the input equals “NIK,” the code will print “You may enter!” Otherwise it prints “Nothing to see here.”

These commands are similar to Ruby. For now, as you look at the code, note some of its styling characteristics:

  • Less punctuation: Python, unlike JavaScript, does not have curly braces, and unlike HTML, does not have angle brackets.

  • Whitespace matters: Statements indented to the same level are grouped together. In the preceding example, note how the if and else align, and the print statements below each are indented the same amount. You can decide the amount of indentation, and whether to use tabs or spaces, as long as you are consistent. Four spaces from the left margin is considered the norm.

    See Python style suggestions on indentation, whitespace, and commenting.

  • A new line indicates the end of a statement: Although you can use semicolons to put more than one statement on a line, the preferred and more common method is to put each statement on its own line.

  • A colon separates a code block: Some new Python programmers wonder why they should use colons to indicate code blocks, like the one at the end of the if statement, when using newlines would suffice. Early user testing with and without the colons showed that beginner programmers better understood the code with the colon.

If you can’t wait, check out Code Academy or for some free, short, self‐taught lessons.