>>> s = ""
>>> a = s or "not none"
>>> a
'not none'
>>> s = None
>>> a = s or "not none"
>>> a
'not none'
>>> s = "aa"
>>> a = s or "not none"
>>> a
'aa'
方式2
>>> s = None
>>> a = "not null" s None s
>>> a
'not null'
>>> s = "aa"
>>> a = "not null" s None s
>>> a
'aa'
好像 方式2 更接近 "? :" 这种 3元表达式
最新评论