+ 4

Walrus Operator

What is walrus operator in python3?

14th Jul 2019, 1:36 PM
Sahil Hadke
Sahil Hadke - avatar
1 Resposta
+ 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
14th Jul 2019, 2:07 PM
unChabon
unChabon - avatar