Hi there !
Can someone explain me the following behaviour ? l = [] 0 in (l is False)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iterable argument required (0 in l) is False
True 0 in l is False
False
This is really obscur to me...
--
Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org 10 1731
>>>> l = [] 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required
that should be clear - 0 in False can't work. (0 in l) is False True 0 in l is False
False
It seems to stem from a behaviour python exhibits in expressions like this:
3 > 2 > 1
This yields True, while
(3 > 2 ) > 1
yields false. Chaining of operators gets translated like this:
3 > 2 and 2 > 1
Look in section 5.9 of the language reference.
Then your expression gets translated to:
0 in l and l is False
which yields False of course.
--
Regards,
Diez B. Roggisch
Sylvain Thenault wrote: Hi there !
Can someone explain me the following behaviour ?
l = [] 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required (0 in l) is False True 0 in l is False False
This is really obscur to me...
From the language reference (5.9 Comparisons):
comparison ::= or_expr ( comp_operator or_expr )* comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!=" | "is" ["not"] | ["not"] "in"
...snip...
Formally, if a, b, c, ..., y, z are expressions and opa, opb, ..., opy are comparison operators, then a opa b opb c ...y opy z is equivalent to a opa b and b opb c and ... y opy z, except that each expression is evaluated at most once.
In other words '0 in l is False' is equivalent to '0 in l and l is False'.
On Tue, 30 Nov 2004 14:18:30 +0100, Diez B. Roggisch wrote: > l = [] > 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required
that should be clear - 0 in False can't work.
yes, I forget to mention that it was the third expression which was
bugging me. > (0 in l) is False True> 0 in l is False False
It seems to stem from a behaviour python exhibits in expressions like this:
3 > 2 > 1
This yields True, while
(3 > 2 ) > 1
yields false. Chaining of operators gets translated like this:
3 > 2 and 2 > 1
Look in section 5.9 of the language reference.
Then your expression gets translated to:
0 in l and l is False
which yields False of course.
thanks, I had missed this part of the language reference !
Not yet found an misbehaviour in python... ;)
--
Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org
>>>>>> (0 in l) is False True
This gives me the same exception.
0 in 1
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iterable argument required
Did you really try these examples?
Best,
Laci
mailto:ga*****@geochemsource.com
web: http://designasign.biz
Tuesday, November 30, 2004, 3:15:27 PM, you wrote: >>> (0 in l) is False True
This gives me the same exception.
0 in 1 Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required
Sorry, It was 0 in l, not 0 in 1. :-)
My fault.
Best,
Laci
mailto:ga*****@geochemsource.com
web: http://designasign.biz
"Laszlo Zsolt Nagy" <ga*****@geochemsource.com> wrote in message
news:ma**************************************@pyth on.org... Did you really try these examples? l is 1
False
Sylvain Thenault wrote: l = [] 0 in (l is False)
(l is False) is not a tuple or list, it's a boolean value. Traceback (most recent call last): File*"<stdin>",*line*1,*in*? TypeError: iterable argument required (0 in l) is False
True
0 in l is False becuase l is empty, so it's False is False which is true,
(except in Intercal probably and Visual C++)
0 in l is False
False
l is False is False because l is not the value false though it has a false
value (err.....)
Okay.
l != False because it's not the displayed value false
but if not l would evaluated to true because [] is a false equivalent.
0 in False .... okay.... this should be an error ..... something to do with
the equivalence confusion of what False is ?
Sylvain Thenault wrote: Hi there !
Can someone explain me the following behaviour ?
l = [] 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required (0 in l) is False True 0 in l is False
False
This is really obscur to me...
A suggestion:
When discussing things on the newsgroup (and in your code), avoid
symbols like "l" and "O" -- they look too much like numbers. Picking
an actual name is best (but depends on your application context).
Second best are names like: "lst", "obj", ...: often, however, such
names are necessary when discussing abstract code properties.
-Scott
"Paul Robson" <au******@autismuk.muralichucks.freeserve.co.uk> wrote in
message news:co**********@news8.svr.pol.co.uk... Sylvain Thenault wrote:
> l = [] > 0 in (l is False) (l is False) is not a tuple or list, it's a boolean value.
Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument required> (0 in l) is False True
0 in l is False becuase l is empty, so it's False is False which is true, (except in Intercal probably and Visual C++) 0 in l is False False
l is False is False because l is not the value false though it has a false value (err.....)
Okay.
l != False because it's not the displayed value false
but if not l would evaluated to true because [] is a false equivalent.
0 in False .... okay.... this should be an error ..... something to do with the equivalence confusion of what False is ?
It's not an error. As one of the first responders said, check
the language definition. That defines both 'in' and 'is'
as equality operators, and defines exactly what a chain
of equality operators means.
In this case, it means:
(0 in l) and (l is False)
The and short circuits, giving the result of False without
ever doing the final comparison.
Granted, that's not exactly obvious...
John Roth
John Roth wrote: It's not an error. As one of the first responders said, check the language definition. That defines both 'in' and 'is' as equality operators, and defines exactly what a chain of equality operators means.
In this case, it means:
(0 in l) and (l is False)
The and short circuits, giving the result of False without ever doing the final comparison.
Granted, that's not exactly obvious...
Thanks ; you learn something every day :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JKop |
last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non-
portable"?
signed main()
{
signed char chedder = 130;
}
Relevant information:
|
by: Bradley Plett |
last post by:
I have what should be a trivial problem. I am using XMLSerializer to
serialize an object. It serializes boolean values as "True" and
"False". I then want to use an XSLT on this XML, and I want...
|
by: Carpe Diem |
last post by:
Hello I have an aspx page that loses Session("user") value after a few
minutes even after I set
<sessionState mode="InProc" cookieless="false" timeout="300"> in web.config
and wrote
function...
|
by: kurtj |
last post by:
Hello Gurus:
I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word...
|
by: André |
last post by:
Hi,
I put that question already, but it's still not very clear to me, so ...
Assume following option in web.config=
debug="false"
but in one aspx page (test.aspx)
<%@ debug="true" ..%>
|
by: Saizan |
last post by:
Why subclassing bool from int either __invert__ or __neg__ haven't been
overrided to produce a boolean negation? I suspect backwards
compatibility or something alike, but I still wonder..
And...
|
by: sherifffruitfly |
last post by:
Hi,
I'm using an adaptation of excel-reading code that's all over the
internet - I don't much like or understand it, but it has worked for me
in the past.... beggars can't be choosers... :
...
|
by: Jamey Bon |
last post by:
As a newbie to C#, I am not sure what I can do about this. I would like to
do something like an Enumeration to use "constants" like Yes to indicate
true and No for false. But since there seems to...
|
by: dangt85 |
last post by:
Hello,
I have the following page:
...
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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,...
| |