What is the official name of this design?

In python:

>>> a = b or {}
+5
source share
5 answers

I don't think it has an official name, it's just a smart / lazy way to be concise. This is roughly equivalent to:

a = b if b else {}

or

if b:
    a = b
else:
    a = {}

I wrote this as a comment, but I think it's worth mentioning here:

. , - None, is None , . , None - , false . 0, [], {},... false. , , .

:

a = b if b is not None else {}
+10

b or {} - OR. , , :

x or y x; x , ; y .

( , and, or , False True, . , , s , , , s or 'foo' . not , , , , , not 'foo' False, ''.)

+2

, , . ,

 (b or {}) 

.

, b False, a {} ( ), b.

+1

+1
source

All Articles