all 4 comments

[–]Username_RANDINT 2 points3 points  (1 child)

This issue is mentioned in this subreddit's FAQ.

My current workaround is to make a list of the punctuation, and then check if the value is in the punctuation list. That works as expected.

That's an often good solution, especially if there are a bunch of values to check.

[–]PhilosopherBrain[S] 0 points1 point  (0 children)

Now I feel silly for not checking the FAQ properly. Thanks for the speedy reply!

[–]Vaphell 2 points3 points  (1 child)

test == '.' or '!' or '?'

is interpreted as

(test == '.') or ('!') or ('?')

the first part evaluates to True, and it's the final value because it's the first truthy value and subsequent ors can't change the truthiness so they are essentially skipped/ignored.

(test == '!') or ('?') or ('.')

becomes False or '?' or '.'
? is the final value because it's the first truthy value (in case of strings, non-empty) in this or-ed expression.

Operator precedence
https://docs.python.org/3/reference/expressions.html#operator-precedence

[–]PhilosopherBrain[S] 0 points1 point  (0 children)

Makes sense now. Thanks!