MemotivaCommon pitfalls and best practices

What does the principle of least surprise mean for Python code?

Common pitfalls and best practices

Audio flashcard · 0:15

Nortren·

What does the principle of least surprise mean for Python code?

0:15

The principle of least surprise says that code should behave the way a reader would expect. Use idiomatic patterns, follow conventions, give variables clear names, and avoid clever tricks that confuse readers. Code is read more often than it is written, so optimize for clarity. ---
peps.python.org