返回不一樣值的小技巧

>>> 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'
>>> 
相關文章
相關標籤/搜索