To check for the existence of a substring, use "in" not "find"
If you just need to check if a string contains a substring, use:
if 'sub' in substring:
instead of:
if substring.find( 'sub' ) != -1:
These work the same in the background, but the first is much easier to understand and shorter to write.
Written by Andrew Giles
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#