Exercise 72
Write a python function which examine if a particular substring occurs within a given string.
Solution
"""
the function is_substring_present takes two arguments: string, which represents the given string, and sub, which represents the substring that we want to check if it occurs within string.
"""
# Python function to check if a particular substring occurs within a given string
def is_substring_present(string, sub):
if sub in string:
return True
else:
return False
# Example of use of this algorithm
string = "Python programming language"
sub = "prog"
if is_substring_present(string, sub):
print(f"{sub} is present in {string}")
else:
print(f"{sub} is not present in {string}")
# output: 'prog' is present in 'Python programming language'
Younes Derfoufi
CRMEF OUJDA
[…] Exercise 72 || Solution […]