返回不同值的小技巧
>>> 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'
>>>
浙公网安备 33010602011771号