我正在尝试执行以下逻辑:
bitmap_id = 'HelloWorld'
if 'SLIDE' not in bitmap_id and 'ICON' not in bitmap_id and 'BOT' not in bitmap_id:
print bitmap_id
Run Code Online (Sandbox Code Playgroud)
因此,如果bitmap_id为'ICON_helloworld',则不应打印任何内容.
我很确定你们都同意它太长并且看起来很难看,所以我试着按照下面的说明进行操作,但它不起作用.
if any(s not in bitmap_id for s in ['SLIDE', 'ICON', 'BOT']):
print bitmap_id
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
使用其中之一
if all(s not in bitmap_id for s in ['SLIDE', 'ICON', 'BOT']):
print bitmap_id
Run Code Online (Sandbox Code Playgroud)
要么
if not any(s in bitmap_id for s in ['SLIDE', 'ICON', 'BOT']):
print bitmap_id
Run Code Online (Sandbox Code Playgroud)