Skip to content

String contains equivalent in Python

In languages like C# or Java, the String class has a Contains() method to check if a certain substring is contained in the string. Python has an equivalent for this that is using the in operator:

foo_bar = "foo bar"
if "bar" in foo_bar:


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.