473,729 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Similar topics

188
8487
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 2.4 installer for windows. Now I have problems to compile python extension that some packages
20
2222
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, Data Controls, User Controls etc. all breaks down the same way: lots of cons very few pros.
17
1828
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 this was? Thanks! -Cloy
0
930
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 about the SigEx Ventures company, an organisation that appoints itself as the liaison between strategic investors and young tallented people in IT&C. It originates in the US but currently operates in Europe. Specifically in Pau, France. On their...
15
1966
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 a, b, c; a = b + c;
54
3936
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 parentheses. 1) "The order of evaluation of subexpressions is determined by the precedence and grouping of operators."
17
1489
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; func(out arr1, out arr2);
39
5072
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
2873
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 it get evaluated sometimes?
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9154
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8156
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.