Search⌘ K

First Things First!

Explore how to use Python's Walrus operator introduced in version 3.8 to assign values within expressions effectively. Understand syntax rules and limitations like parenthesizing restrictions and why some forms cause errors. This lesson helps you write cleaner, more concise code using assignment expressions.

We'll cover the following...

Python 3.8’s “Walrus” operator (:=) was quite popular. Let’s check it out.

C++
a = "ftw_walrus"
print(a)
C++
a := "ftw_walrus" # doesn't work
C++
(a := "ftw_walrus") # This works though
print(a)

Explanation

The Walrus operator (:=) was introduced in Python 3.8, it can be ...