看来,如果数组中只有一项,那么数组上的操作符"in"不仅会匹配整个字符串.该行为与"list"和"set"不同. 我不明白区别从何而来,是设计有一些特定用途还是一个错误?
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> skip_funcs = ("ENG_EN1") # mis-match in tuple
>>> "ENG" in skip_funcs
True
>>> skip_funcs = ("ENG_EN1", "abc") # correct if the tuple has more than one component
>>> "ENG" in skip_funcs
False
>>> "ENG_EN1" in skip_funcs
True
>>> skip_funcs = ["ENG_EN1"] # correct for 'list'
>>> "ENG" in skip_funcs
False
>>> "ENG_EN1" in skip_funcs
True
>>> skip_funcs = {"ENG_EN1"} # correct for 'set'
>>> "ENG" in skip_funcs
False
>>> "ENG_EN1" in skip_funcs
True