0

What is the proper way to verify there is no space in a string and then print an error message?

I do not know the corerct if, then statement for verify space in a string.

  • have a look to `str.isspace`: it detects white spaces, `\t`, `\n`,... – cards Feb 14 '23 at 18:19
  • To detect at least one space (ASCII 32), use `if ' ' in mystring:` – pts Feb 14 '23 at 18:21
  • To detect at least one whitespace, use `import re` followed by `if re.search(r'\s'):` – pts Feb 14 '23 at 18:23
  • To detect all whitespace, non-empty: use `if mystring.isspace():` – pts Feb 14 '23 at 18:26
  • BTW, welcome to Stack Overflow! Check out the [tour] and [How to ask a good question](/help/how-to-ask), which has tips like starting with your own research. – wjandrea Feb 14 '23 at 21:20

0 Answers0