w3resource

Python: Check whether a string starts with specified characters

Python String: Exercise-24 with Solution

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/string/python-data-type-string-exercise-24.php