The Walrus Operator in Python

Learn what the walrus operator is and how to use it in Python

Luay Matalka
Towards Data Science
4 min readMar 5, 2021

--

Photo by Jay Ruzesky on Unsplash

The walrus operator, introduced in Python 3.8, offers a way to accomplish two tasks at once: assigning a value to a variable, and returning that value, which can sometimes offer a way to write shorter, more readable code, that may even be more computationally efficient.

--

--

Lead Machine Learning Engineer, specializing in MLOps, with a passion for teaching.