返回不同值的小技巧

>>> hobbies = ['software']
>>> ('notchecked', 'checked')['software' in hobbies]
'checked'
>>> 'checked' if 'software' in hobbies else 'notchecked'
'checked'
>>> hobbies = ['xxx']
>>> 'checked' if 'software' in hobbies else 'notchecked'
'notchecked'
>>> 

 

posted @ 2017-02-10 16:36  鸪斑兔  阅读(144)  评论(0编辑  收藏  举报