如何检查 python 上的尾随空格?

Joy*_*Lam 1 python string whitespace syntax-checking

我正在尝试编写一个函数来检查尾随空格,但不删除空格。但我不知道该怎么做。有人可以教我吗?

谢谢

fal*_*tru 5

使用str.endswith

>>> 'with trailing space  '.endswith(' ')
True
>>> 'without trailing space'.endswith(' ')
False
Run Code Online (Sandbox Code Playgroud)