php三元表达式:[Python 学习笔记] 3: 3元表达式?

  方式1

>>> 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元表达式

Tags:  php三元表达式

延伸阅读

最新评论

发表评论