Check if string begins with substring give wrong output

66 Views Asked by At

I'm trying to match only the strings that begins with %%ABC XYZ: or %%RLMI UUEW:, but I don't know why I'm getting true in Out[1] when I use startswith() with a tuple and the string actually doesn't have the %% at the beginning.

'ABC XYZ:0882-928'.startswith(('%%RLMI UUEW:','%%ABC XYZ:'))
Out[1]: True

'%%ABC XYZ:0882-928'.startswith(('%%RLMI UUEW:','%%ABC XYZ:'))
Out[2]: True

When startswith() is used with a single sub string, the output is correct. Why? thanks in advance.

'ABC XYZ:7281-001'.startswith('%%ABC XYZ:')
Out[3]: False

'%%ABC XYZ:7281-001'.startswith('%%ABC XYZ:')
Out[4]: True

UPDATE

import sys

print("User Current Version:-", sys.version)
User Current Version:- 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]
0

There are 0 best solutions below