473,729 Members | 2,144 Online

# Evaluation of Truth Curiosity

Hello All,

I'm curious, in

py0 | (1 == 1)
1
pyFalse | (1 == 1)
True

What is the logic of the former expression not evaluating to True (or
why the latter not 1?)? Is there some logic that necessitates the first
operand's dictating the result of the evaluation? Or is this an artefact
of the CPython implementation?

James
Sep 21 '06 #1
4 1137
James Stroud wrote:
What is the logic of the former expression not evaluating to True (or
why the latter not 1?)? Is there some logic that necessitates the first
operand's dictating the result of the evaluation? Or is this an artefact
of the CPython implementation?
If I understand correctly, OR'ing an int and a bool (your first
example) returns an int by coercing the bool to an int; and OR'ing two
bools (your second example) returns a bool.

Regards,
Jordan

Sep 21 '06 #2
James Stroud a écrit :
Hello All,

I'm curious, in

py0 | (1 == 1)
1
pyFalse | (1 == 1)
True

What is the logic of the former expression not evaluating to True (or
why the latter not 1?)? Is there some logic that necessitates the first
operand's dictating the result of the evaluation? Or is this an artefact
of the CPython implementation?

James
| is the binary or operator, not the truth value operator. Also, True ==
1 and False == 0. Always use the "or" and "and" keywords for truth
operations.
Sep 21 '06 #3
James Stroud wrote:
I'm curious, in

py0 | (1 == 1)
1
pyFalse | (1 == 1)
True

What is the logic of the former expression not evaluating to True (or
why the latter not 1?)? Is there some logic that necessitates the first
operand's dictating the result of the evaluation? Or is this an artefact
of the CPython implementation?
looks like you're confusing binary or ("|") with logical or ("or").

binary or on booleans are only defined for boolean | boolean; for any
other combination, the usual coercion rules apply.

</F>

Sep 21 '06 #4
Everyone wrote:
[something intelligent]
Ah, clarity. My confusion can undoubtedly be traced to a non-existent
formal training in computer programming.

Thank you.
Sep 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.