Check if space is in a string

前端 未结 4 961
醉酒成梦
醉酒成梦 2021-02-11 14:21
\' \' 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

4条回答
  •  青春惊慌失措
    2021-02-11 14:47

    You can try this, and if it will find any space it will return the position where the first space is.

    if mystring.find(' ') != -1:
        print True
    else:
        print False
    

提交回复
热议问题