The Zen of Python
A hidden message inside Python: its design ideas in 19 lines. Read the first seven carefully.
Python is a free, general-purpose programming language designed to be easy to read. It is the main language of AI and data work because it is quick to write and because its heavy number-crunching is done by fast libraries written in C, which Python code drives.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a program with a list of three temperatures, [31, 18, 25], that prints each temperature followed by warm if it is 25 or more and cool otherwise.
Using the standard library, print the average and the highest of the prices [120, 80, 100].
Without running it, say what this prints, then check: import math followed by print(math.sqrt(81)).
Explain it without notes
What kind of language is Python? Describe it in three or four properties.
Why is Python the main language of AI even though it is slower than C or Java?
What does "batteries included" mean?
Name two kinds of software for which Python is usually not the first choice, and say why.
Expected output
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!