How to check if a string contains substring in Python

4 Answers

0 votes
if "th" in "python": 
  print('contain')
else:
  print('not contain')


 
'''
run:
 
contain
  
'''

 



answered Jul 30, 2019 by avibootz
0 votes
if "th" not in "python": 
  print('not contain')
else:
  print('contain')


 
'''
run:
 
contain
  
'''

 



answered Jul 30, 2019 by avibootz
0 votes
s = "python programming"

if s.find("python") == -1:
    print("Not Found")
else:
    print("Found")


 
'''
run:
 
Found
  
'''

 



answered Jul 30, 2019 by avibootz
0 votes
s = "python programming"

if s.find("python") != -1:
    print("Found")
else:
    print("Not Found")


 
'''
run:
 
Found
  
'''

 



answered Jul 30, 2019 by avibootz

Related questions

2 answers 287 views
1 answer 179 views
1 answer 201 views
1 answer 286 views
1 answer 253 views
1 answer 193 views
...