Python determines whether a string contains a sub-string.
This example describes how to use python to determine whether a string contains a sub-string. Share it with you for your reference. The details are as follows:
The string object in python does not have the contains method. You do not need to use the string. contains method to determine whether a sub-string is contained. However, python has a simpler method to replace the contains function.
Method 1: Use the in method to implement the contains function:
Site = 'HTTP: // www.bkjia.com/'if "jb51" in site: print ('site contains jb51 ')
Output result: site contains jb51
Method 2: Use the find function to implement the contains Function
S = "This be a string" if s. find ("is") =-1: print "No 'is' here! "Else: print" Found 'is' in the string ."
I hope this article will help you with Python programming.