Google News
logo
Python Program to Search a string to see if it starts with "The" and ends with "Spain"
In the following example of Python program that searches a string to see if it starts with "The" and ends with "Spain" :
Program :
string = "The quick brown fox jumps over the lazy dog in Spain"
if string.startswith("The") and string.endswith("Spain"):
    print("The string starts with 'The' and ends with 'Spain'")
else:
    print("The string does not start with 'The' and end with 'Spain'")
Output :
The string starts with 'The' and ends with 'Spain'
In this program, we define a string variable and use the `startswith()` and `endswith()` methods to check if the string starts with "The" and ends with "Spain", respectively.

If both conditions are true, we print a message saying that the string starts with "The" and ends with "Spain". Otherwise, we print a message saying that the string does not meet the conditions.