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! :)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With