且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python-检查字符串中的多个空格

更新时间:2023-02-26 20:39:28

如果要使用repr()打印text的内容,您将看到它不包含两个连续的空格:

If you were to print the contents of text using repr(), you will see that it does not contain two consecutive spaces:

'hello \xa0 \xa0 \xa0world '

因此,您的函数正确返回了False.可以通过将不间断空格转换为空格来解决此问题:

As a result, your function correctly returns False. This could be fixed by converting the non-break space into a space:

text = text.replace(u'\xa0', u' ')