Skip to content

Check if a strings starts or end with a specified value

Python has some nice methods to check if your strings start or end with a specified string, with str.startswith() and str.endswith(). They return a boolean whether the strings starts/ends with the specified value:

name = "John Doe"

name.startswith("John") # true
name.endswith("Doe") # true
name.startswith("Jane") # false


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.