s = '种草 '
print(len(s))
s = s.strip()
print(len(s))
And the output for both is '4'. It seems the space takes up 2 characters and can't be removed by the strip() function. It's a Chinese space and can't be removed by the strip function.
It's not a usual unicode space. you can remove it like this.
s = '种草 '
print(len(s))
s = s.strip(u'\u200b').strip()
print(len(s))
strip removes spaces from both ends of a string.
>>> s = '种草 '
>>> ord(s[-1])
8203
>>> ord(s[-2])
32
>>> ord(' ')
32
The last character here is not a space character. The second last character is a space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With