>>> 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'
>>>
转载于:https://www.cnblogs.com/tuzkee/p/6386989.html