How to check if a string contains a substring in Python

The most straightforward way to check if a string contains a substring is to use in (opens new window). You can also use find (opens new window) or index (opens new window) to get the position of the substring you're looking for. If the substring doesn't exist, you'll get a -1.

Copy code
      
    

Join our community

Your sign-up could not be saved. Please try again.
Your sign-up was successful.

Sign-up and get tips to becoming a software engineer.