String

String

startswith()

returns True if the string starts with the specified value:

text = "Hello world" result = text.startswith("Hello") print(result) # True

Optional second and third argument indicates start and end position of the search:

text = "Hello world" result = text.startswith("Hello", 4, 7) print(result) # False

Optional second argument can be an OR search option:

text = "Hi world" result = text.startswith("Hello", "Hi") print(result) # True