- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if a substring is contained in another string in Python
Python has a keyword 'in' for finding if a string is a substring of another string. For example
print('ello' in 'hello world')
If you also need the first index of the substring, you can use find(substr) to find the index. If this method returns -1, it means that substring doesn't exist in the string. For example,
Checking if ‘no’ is contained in the string ‘Harry Potter: The Goblet of Fire'
print("Harry Potter: The Goblet of Fire".find('no'))
- Python - Check if a list is contained in another list
- How to check if string or a substring of string starts with substring in Python?
- Check if a string is suffix of another in Python
- Python Program to check if a substring is present in a given string.
- Check if substring present in string in Python
- How to check if a string is a subset of another string in R?
- How to check if a string contains a substring in Golang?
- How to check if string or a substring of string ends with suffix in Python?
- C# program to check if a Substring is present in a Given String
- Java program to check if a Substring is present in a given String
- Check if a string can be repeated to make another string in Python
- Check if it is possible to transform one string to another in Python
- How to check if multiple strings exist in another string in Python?
- How to check if a string is alphanumeric in Python?
- Java Program to Check if a string contains a substring