How to use str.startswith with multiple strings?

Viewed 1800

I've tried using the or function to input multiple words for the same output, but it only takes the first word as the input and not the rest. How do I solve this? Thanks! For instance:

message.content.startswith("hi" or "hey")

only takes in "hi" as an input and not "hey".

I've tried adding the words in to a list and it doesn't work as well. I'm relatively new to coding so i'm sorry in advance if it's a stupid question

1 Answers

You can code like this:

message.content.startswith(("hi", "hey"))

From the Python documentation for str.startswith(prefix[, start[, end]]), I've added emphasis:

Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.

Related