Check if space is in a string

前端 未结 5 2266
执笔经年
执笔经年 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:48

    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"
    

提交回复
热议问题