Check if space is in a string

前端 未结 4 953
醉酒成梦
醉酒成梦 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:53

    There are a lot of ways to do that :

    t = s.split(" ")
    if len(t) > 1:
      print "several tokens"
    

    To be sure it matches every kind of space, you can use re module :

    import re
    if re.search(r"\s", your_string):
      print "several words"
    

提交回复
热议问题