Check if space is in a string

前端 未结 5 2262
执笔经年
执笔经年 2021-02-11 14:08
\' \' in word == True

I\'m writing a program that checks whether the string is a single word. Why doesn\'t this work and is there any better way to che

5条回答
  •  不思量自难忘°
    2021-02-11 14:37

    You can say word.strip(" ") to remove any leading/trailing spaces from the string - you should do that before your if statement. That way if someone enters input such as " test " your program will still work.

    That said, if " " in word: will determine if a string contains any spaces. If that does not working, can you please provide more information?

提交回复
热议问题