我有一个名为bag的列表.我希望能够检查是否只有特定的项目.
bag = ["drink"]
if only "drink" in bag:
print 'There is only a drink in the bag'
else:
print 'There is something else other than a drink in the bag'
Run Code Online (Sandbox Code Playgroud)
当然,在那里我把'only'放在那里的代码中,这是错误的.有没有简单的替代品?我试过几个相似的词.