473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1124
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.

Similar topics

188
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python...
20
by: John Rivers | last post by:
Hello, I am in the process of evaluating ASP.NET So far I am not impressed at all. It seems to me that a basic evaluation of the PROs and CONs of using things like HTML Server Controls,...
17
by: Cloy | last post by:
At one point, someone posted a really handy four-letter mnemonic for evaluating web sites. It was something like OSDI - something, Structure, something, Interface. Anyone happen to know what...
0
by: sigexfoundry | last post by:
First of all, I'd like to appologise for the noise and for cross-posting. This is my first and last e-mail on this list. As you may have noticed from the subject of the e-mail, I'm about to speak...
15
by: Jeroen | last post by:
Hi all, I've got a very specific question about the evaluation order in C++. Assume some kind of custom array class, with an overloaded subscript operator. In the following code: { my_array...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
17
by: Jon | last post by:
In the following, the second parameter value is put in arr2. Can I assume that the first is also put in arr1 and not arr1? More generally, in C#, at what point is i incremented? int i=2;...
39
by: Boltar | last post by:
Why does C do lazy evaluation for logical boolean operations but not bitwise ones? Ie: the following program prints "1 2" , not "1 1" under gcc main() { int a = 1; int b = 1; 0 && ++a;
30
by: Lassie | last post by:
bool finished = is_done(); if (finished && try_again()) { } Is my understanding of short circuit evaluation correct that if finished is false that try_again() will never be executed? Or does...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.