Reputation:
I have a string color_line
which I need to check whether it starts with a substring which takes values only in 'red'
, 'blue'
, 'green'
, or 'magenta'
.
Is there a shorter way of doing the check than the obvious way of
if line.startswith( 'red' ) or ... or line.startswith( 'magenta' ): ...
Upvotes: 0
Views: 62
Reputation:
You can pass a tuple of values to str.startswith
:
if line.startswith(('red', 'blue', 'green', 'magenta')):
Upvotes: 5