Determine Whether a String Contains a Substring in Python

x = "abcdefg"
 
print "abc" in x // True
print "xyz" in x //False

3 Responses to “Determine Whether a String Contains a Substring in Python”

  1. http://docs.python.org/library/string.html#deprecated-string-functions

  2. bah, the instance method is not being deprecated; anyhoo, (‘foo’ in ‘barfoo’)

  3. This can be finished simply using the “find” method.

Leave a Reply