 <p>We can use python regular expression search module to get it done in efficient way.</p> <pre><code>import re matchobj = re.search(r"xyz",given_text) if matchobj: print "Found" else: print "Not Found" </code></pre>