The Operator That Dethroned a King: Python's Walrus Operator Story

How two characters — a colon and an equals sign — caused Python's creator to resign, reshaped open source governance forever, and eventually became one of the language's most elegant features.

TechLife

Null Coalescing vs Walrus Operator: One-Line Power

PHP's ?? operator vs Python's := walrus operator. Which language gives you more one-line superpowers? Mind = blown!

#php #python #phpvspython #nullcoalescing #walrusoperator #operators #oneliner #programmingcomparison #phptricks #pythontricks #codecomparison #syntaxcomparison #viralcoding

https://www.youtube.com/watch?v=0KmTGH51AW8

Null Coalescing vs Walrus Operator: One-Line Power #codecomparison

YouTube

Nullish Coalescing vs Walrus Operator: Modern Operator Face-Off

JavaScript ?? operator vs Python := walrus operator. Which language's modern operator is more useful? This comparison is INSANE!

#javascript #python #javascriptvspython #nullishcoalescing #walrusoperator #modernoperators #programmingcomparison #codecomparison #javascripttricks #pythontricks #syntaxcomparison #viralcoding #codingshorts #es2020 #python3.8

https://www.youtube.com/watch?v=9ZiNZGWBdw8

Nullish Coalescing vs Walrus Operator: Modern Operator Face-Off #viralcoding

YouTube

Encapsulating the atrocity of umask handling with Python's walrus operator:

os.umask(current_umask := os.umask(0))

This isn't clearly *better*, but at least it's clearly shorter. Without `:=`, we'd need two lines:

current_umask = os.umask(0)
os.umask(current_umask)

Note: The awkwardness is a necessary consequence of how POSIX handles umask. Also, neither version is threadsafe.

#Python #WalrusOperator #umask

would you use the #WalrusOperator?

if test_fit(i, j, s) or test_fit(i, j, s := 1):
fill_grid(i, j, s)

or make it a bit longer like this

if test_fit(i, j, s):
fill_grid(i, j, s)
elif test_fit(i, j, 1):
fill_grid(i, j, 1)

? #Python

one thing I would love for python is to be able to say
if not s := some_query(args):
stuff if the query fails
else:
stuff if the query succeeds and you have s assigned

#python #walrus #walrusoperator

Emily Morehouse-Valcarcel on Twitter

“They’re heeeeeeeere! #WalrusOperator #PyCon2019”

Twitter