vivis vivis avatar dev

> thoughts on AI, code, and everything in between

Koan 9: The Unfired Pot REDUX


This is not your usual Python Koans post. It’s come to my attention that there is some information in Koan 9: The Unfired Pot that is either incorrect or misleading.

Firstly, I’d like to apologize sincerely for letting this slip through the cracks. I try to be as diligent as possible when writing each post, but this one wasn’t my best work. I’ve put some steps in place so that this doesn’t happen again. Also, a big thanks to @vekyll who pointed some of the issues out.

Secondly, I’ve edited the original post to correct those mistakes, but I thought it would be worthwhile to revisit some fundamental concepts underpinning the topic here, and also expand on the corrections.

Python Statements and Expressions

The building blocks of Python are statements. A statement is a block of code which does something. If a statement can fit in one line, it is a Simple Statement, otherwise it’s a Compound Statement.

An expression is a special type of statement which evaluates to a single value:

An expression is an accumulation of expression elements like literals, names, attribute access, operators or function calls which all return a value. In contrast to many other languages, not all language constructs are expressions. There are also statements which cannot be used as expressions, such as while.

from Python Glossary

1. Assignments don’t return values

An assignment is a statement, but it is not an expression. This is because it doesn’t return a value. Some of the text from the original post implied that assignment returns a value. For e.g.


If you're enjoying this post, consider subscribing for more posts like this:


This assignment itself returns the value that was assigned

This is false, assignment never returns a value.

You also can’t use assignments inside expressions like you can in C (like if (x = y)). However, one exception was introduced in Python 3.8. Assignment expressions (also known as the walrus operator) like if (x := y): lets you assign values within an expression.

2. Chained Assignment evaluates RHS, then binds names left -> right

The original post stated that chained assignments are evaluated right to left, but this is misleading. For this example from the original post:

x = 10
x = y = z = x + 2

Python evaluates the right-hand-side x + 2 first, then binds the value to the names from left to right. i.e x, y, and then z last.

Python does not evaluate chained assignment by returning a value from each individual assignment and then reassigning it leftwards.

3. Comparison Chains Do Not Behave Like Assignment Chains

The original post ambiguously stated that chained operations like 1 < x < 10 and chained assignments operate under the same principle:

The same principle applies to chained comparison operators such as <> and ==.

This is false of course, and the rest of the section does gets it right. Comparison chains are essentially syntactic sugar which evaluates to distinct comparisons and-ed together: (1 < x) and (x < 10).


Thanks again for continuing to read Python Koans. I hope you’ve learnt something new along the way. I’ve got lots of great content and a new learning platform planned for the new year. Stay tuned!