Python Check if a substring presents in a string using ‘in’ operator

An example of ‘in’ administrator python: Here, we will figure out how to check whether a substring presents in a string or not?

“in” administrator is a notable and most helpful administrator in a python programming language, it very well may be utilized to check whether a substring is available in a string or not?

Example 1:

Input:
String: "JustTechReview"
Substring to check: "Review"

Output:
Yes, substring presents in the string.

Example 2:

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

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

Program:

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

# string and substring declaration, initialization
str = "JustTechReview.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.	

Leave a Comment

error: Alert: Content is protected!!