用于检查给定字符串中是否存在子字符串的Python程序。
在这个问题中,给出了一个字符串,我们必须检查给定字符串中是否存在子字符串。
算法
Step 1: input a string and a substring from the user and store it in separate variables. Step 2. Check if the substring is present in the string or not. To do this using find() in-built function. Step 3. Print the final result. Step 4. Exit.
范例程式码
def check(str1, sstr):
if (str1.find(sstr) == -1):
print(sstr,"IS NOT PRESENT IN THE GIVEN STRING")
else:
print(sstr,"IS PRESENT IN THE GIVEN STRING")
# Driver code
str1 = input("Enter the string ::>")
sstr=input("Enter Substring ::>")
check(str1, sstr)输出结果
Enter the string ::> python program Enter Substring ::> program program IS PRESENT IN THE GIVEN STRING Enter the string ::> python program Enter Substring ::> programming programming IS NOT PRESENT IN THE GIVEN STRING
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短