Pylint complains about comparing a string to a literal with 'is'
本问题已经有最佳答案,请猛点这里访问。
请考虑以下代码段:
1 2 | my_string = 'asdf' print(my_string is 'xfje') #R0123 |
pylint在第二行返回一个建议
literal-comparison (R0123):
Comparison to literal Used when comparing an object to a literal, which is usually what you do not want to do, since you can compare to a different literal than what was expected altogether.
这个解释对我一点帮助都没有。我知道在两个字符串对象之间使用
我为什么不在这里使用
请考虑以下示例:
1 2 3 4 5 6 7 | >>> my_string = ''.join([c for c in 'xfje']) >>> print my_string xfje >>> print my_string == 'xfje' True >>> print my_string is 'xfje' False |