This is a Python Program to check if a substring is present in a given string.
The program takes a string and checks if a substring is present in the given string.
1. Take a string and a substring from the user and store it in separate variables.
2. Check if the substring is present in the string using find() in-built function.
3. Print the final result.
4. Exit.
Here is source code of the Python Program to calculate the length of a string without using library functions. The program output is also shown below.
string=raw_input("Enter string:") sub_str=raw_input("Enter word:") if(string.find(sub_str)==-1): print("Substring not found in string!") else: print("Substring in string!")
1. User must enter a string and a substring from the user and store it in separate variables.
2. It is then checked if the substring is present in the string using find() in-built function.
3. An if statement is used to make the decision and the final result is printed.
Case 1: Enter string:Hello world Enter word:world Substring in string! Case 2: Enter string:Hello world Enter word:apple Substring not found in string!
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Apply for Programming Internship
- Apply for Python Internship
- Check Python Books
- Check Information Technology Books
- Practice Programming MCQs