Walrus Operator(:=) in Python

PHOTO EMBED

Thu Feb 13 2025 21:53:44 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

while ( user_input := input("Enter something (or 'quit' to exit): ") ) != "quit":
    
    print(f"You entered: {user_input}")
content_copyCOPY

The Walrus operator was introduced in Python 3.8. It allows you to assign values to variables as a part of an expression. We can use it to create, assign and use variables in the same statement.

https://www.pynerds.com/walrus-operator-in-python/