Python help, string within another based on starting point

String 1 = ‘text1/text2/text3’
String 2 = ‘text2’
String 3 = ‘text1/text2’

I would like to compare two strings, but start from the left, so using the ‘in’ operator isn’t much good. Using the three strings, comparing String 1 and 2, would return false, comparing String 1 and 3 would return true. Are there built-in python functions that can accomplish this? I’m not sure the best way to ask this question so my usual Google search comes up empty.

Any help is much appreciated.

Strings in python have a .startswith method.


Additionally there’s an .endswith for the other direction.

1 Like

Perfect, thank you both.