返回顶部

收藏

Using the and-or Trick Safely

更多
a = '' 
b = 'second' 
print (1 and [a] or [b])[0]

# Since [a] is a nonempty list, it is never false. Even if a is 0 or '', 
# or some other false value, the list [a] is true because it has one element.

标签:Python,基础

收藏

0人收藏

支持

0

反对

0

发表评论