WebMasterCampus
WEB DEVELOPER Resources

Python String Contains Substring Method

Learn how Python check string contains substring using in operator


Python Substring Using in Operator

Python has a comparison operator “in” that you should use when need to find availability of a substring inside a string. The keyword “in” is used as a comparison operator.

Check Substring Using in operator


if "world" in "webmastercampus": 
    continue

The opposite (complement), which the original question asks for, is not in:


if "world" not in "webmastercampus": 
    continue

Check Substring Using find() Function

message = "This be a sub-string"
if message.find("is") == -1:
    print("'is' not available in message")
else:
    print("'is' available in message")
Created with love and passion.