标签: python string
我有一个字符串color_line,我需要检查它是否以子字符串开头,该子字符串仅在'red','blue','green'或{{1 }}。
color_line
'red'
'blue'
'green'
与
'magenta'
答案 0 :(得分:5)
您可以将值元组传递给str.startswith:
str.startswith
if line.startswith(('red', 'blue', 'green', 'magenta')):