search a white space in string in python by R4R Team


program-

import re

print("Enter string")
s=input()

#first way
for i in s:
if i==" ":
print("There is a white space in between the string")
i=0
break
if i!=0:
print("No white space present in string")


#second way using regular expression
x=re.search("s",s)
if x:
print("There is a white space in between the string")
else:
print("No white space present in string")


output-

Enter string
this is the string
There is a white space in between the string
There is a white space in between the string

Enter string
programming
No white space present in string
No white space present in string


-In this program, we try to find the white space in the input string.
-In first way, we iterate the whole string by the for loop and when the if condition is true then we break the loop and print desire output.
-In second way,we use regular expression idea in which search() function search the required pattern in the given string by re.search("s",string).
-In first output, string is "This is the string", so there are white space present in this string so we print desire output.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!