KnowledgeBoat Logo
|

Computer Science

Write the output of the following:

string = "Hello Madam, I love Tutorials"
substring = "Madam"
if string.find(substring) != -1:
    print("Python found the substring!")
else:
    print("Python did NOT find the substring!")

Python

Python String Manipulation

4 Likes

Answer

Python found the substring!

Working

The code checks if the substring "Madam" exists in the string "Hello Madam, I love Tutorials" using the find() method. Since "Madam" is present in the string, find() returns the starting index of "Madam", which is not -1. Therefore, the condition string.find(substring) != -1 evaluates to True, and the code prints "Python found the substring!".

Answered By

2 Likes


Related Questions