You can use letter in 'OQ' or re.match('[OQ]', letter)
In more detail, I would probably define a string of prefixes that should receive "u".
prefixes = 'JKLMNOPQ' prefixes_taking_u = 'OQ' suffix = 'ack' for p in prefixes: u_part = 'u' if p in prefixes_taking_u else '' print p + u_part + suffix
In your code, letter == ("O" or "Q") first evaluates ("O" or "Q") ("O" is not false, therefore the result is "O"), and therefore it is the same as letter == "O" .
Your other attempt letter == "O" or "Q" first evaluates letter == "O" , and if it is true, it gives the True answer, otherwise it will give the answer "Q".
You can find documentation on how or works in the help system.
user97370
source share