Q:

Python | Check if a substring presents in a string using \'in\' operator

belongs to collection: Python String Programs

0

Example 1:

Input:
String: "IncludeHelp.com"
Substring to check: "Help"

Output:
Yes, substring presents in the string. 

Example 2:

String: "IncludeHelp.com"
Substring to check: "Hello"

Output:
No, substring does not present in the string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# python program to check substring 
# presents in the string or not

# string and substring declaration, initialization
str = "IncludeHelp.Com"
sub_str ="Help"

# checking sub_str presents in str or not
if sub_str in str:
	print("Yes, substring presents in the string.")
else:
	print("No, substring does not present in the string.");

# testing another substring
sub_str = "Hello"	

# checking sub_str presents in str or not
if sub_str in str:
	print("Yes, substring presents in the string.")
else:
	print("No, substring does not present in the string.");

Output

Yes, substring presents in the string. 
No, substring does not present in the string.	

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Assign Hexadecimal values in the string a... >>
<< Python | Concatenate two strings and assign in ano...