我将尝试在Python中比较两个字符串,并注意到当字符串中存在连字符/破折号时,它们不会相等。例如:
然后,如果我添加一个破折号
为什么会这样,以及用什么方法最好比较带破折号的字符串?
>>>teststring = 'newstring'
>>>teststring is 'newstring'
True
然后,如果我添加一个破折号
>>>teststring = 'new-string'
>>>teststring is 'new-string'
False
为什么会这样,以及用什么方法最好比较带破折号的字符串?
==
。 - Martijn Pieters