In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
In [1]: import re
In [2]: string = "Hello world"
In [3]: bool(re.search('s', string))
Out[3]: True
In [4]: string = "World"
In [5]: bool(re.search('s', string))
Out[5]: False
how to check if a string contains spaces in python
#isspace() is a built-in method used for string handling
string = "My name is"
print(string.isspace())
#It will print True
string = "Hello"
print(string.isspace())
#It will print True