Friday, 1 September 2017

Does Python have a string 'contains' substring method?





I'm looking for a string.contains or string.indexof method in Python.



I want to do:



if not somestring.contains("blah"):
continue


Answer



You can use the in operator:



if "blah" not in somestring: 
continue

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...