I want a code that will detect if there is whitespace at the end of a string in Python and return a true or false so it can be used in a conditional, is there a way to do this? Thanks! :)
Asked
Active
Viewed 67 times
1 Answers
6
You can try:
your_string.endswith(" ")
But, if you want to match any kind of white space, you can use:
import re
re.match(r".*\s$", your_string)
re.UNICODE
flag can be also useful if you work with Python 2:
import re
re.match(r".*\s$", your_string, flags=re.UNICODE)

Laurent LAPORTE
- 21,958
- 6
- 58
- 103