Reputation: 503
is there a function in python to check whether a string starts with a certain number of possibilities?
For example, I'd like to check whether string A starts with "Ha", "Ho", "Hi". I thought I could use string_A.startswith("Ha", "Ho", "Hi")
, but unfortunately, this is not possible :(
Thanks for any advice! :)
Upvotes: 4
Views: 6107
Reputation: 369134
You need to pass them as a single tuple:
>>> "Hi, there".startswith(('Ha', 'Ho', 'Hi'))
True
>>> "Hoy, there".startswith(('Ha', 'Ho', 'Hi'))
True
>>> "Hello, there".startswith(('Ha', 'Ho', 'Hi'))
False
Upvotes: 13