Walrus Operator | Sololearn: Learn to code for FREE!

+4

Walrus Operator

What is walrus operator in python3?

7/14/2019 1:36:32 PM

Sahil Hadke

1 Answer

New Answer

+5

:= It's one of the new features of python (3.8 for testing tho... ) "...since := is an expression, it can be used in contexts where statements are illegal, including lambda functions and comprehensions..." * i.e. It allows to assign a value to a variable in a condition*: # python 3.7 m = pattern.search(w)) If m is not None: process(m) # using := if (m := pattern.search(w)) is not None: process(m) *https://www.python.org/dev/peps/pep-0572/#differences-between-assignment-expressions-and-assignment-statements