AI engineering glossary · Python core

What is walrus operator?

Walrus operator (also called assignment expression): The := operator, introduced in Python 3.8, which assigns a value to a name as part of an expression. It lets you compute a value once, use it in a condition, and reuse it without a separate statement.

Level: advancedTopic: Python core

Walrus operator: an example

if (n := len(data)) > 10: print(n) computes the length once and reuses it inside the block.

Related terms

More Python core terms

Where you learn it

Walrus operator is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.