Write a Python program to check whether a string starts with specified characters


This program is written in the Python programming language and it checks if a given string starts with a specified prefix. It does this in two steps:

  • The first step is to define the input string "str".
  • The program then uses the "startswith" method to check if the string "str" starts with the prefix "Tu". The "startswith" method returns a boolean value indicating whether the string starts with the specified prefix or not. The result of the first "startswith" method call is then printed to the console using the "print" function.
  • The program repeats step 2 for another prefix "tur" and the result of the second "startswith" method call is then printed to the console using the "print" function.

Source Code

str = "Tutor Joes Computer Education"
print(str.startswith("Tu"))
print(str.startswith("tur"))

Output

True
False


Example Programs