w3resource

Python: Check whether a string starts with specified characters


Check if string starts with specified chars.

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

Python String Exercises: Check whether a string starts with specified characters

Sample Solution:

Python Code:

# Define a variable 'string' and assign it the value "w3resource.com".
string = "w3resource.com"

# Use the startswith() method to check if the string 'string' starts with the substring "w3r".
# The result is a boolean value, which is printed.
print(string.startswith("w3r"))

Sample Output:

True

Python Code Editor:

Previous: Write a Python program to remove a newline in Python.
Next: Write a Python program to create a Caesar encryption.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.