Fred
Fred

Reputation: 13

If statement with both 'and' and 'or'

I want my if statement to evaluate True if answers[3] == 'Friday' and if answers[4] equals either of '13-15' or '15-17'

Is below form correct?

if (answers[3] == 'Friday' and (answers[4] == '13-15' or answers[4] == '15-17')):

Upvotes: 0

Views: 95

Answers (1)

Kasravnd
Kasravnd

Reputation: 107297

Yes it's correct, and you can use a set container in order to make the or statement more concise.

if answers[3] == 'Friday' and answers[4] in {'13-15', '15-17'}:

Upvotes: 1

Related Questions