find common string in two strings python 1

find common string in two strings python

for i in str1: 
        if i in str2:
      			return "TRUE"

Here is what the above code is Doing:
1. It’s taking the first character of the first string and comparing it to the first character of the second string.
2. If the first character of the first string is not in the second string, it moves on to the second character of the first string and compares it to the first character of the second string.
3. If the second character of the first string is not in the second string, it moves on to the third character of the first string and compares it to the first character of the second string.
4. This process continues until the first character of the first string is found in the second string.
5. If the first character of the first string is not found in the second string, the function returns “FALSE”.

Similar Posts