1 0 == True - False

2014-01-30 Thread Thibault Langlois
Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type help, copyright, credits or license for more information. 1 0 == True False (1 0) == True True 1 (0 == True) True What am I missing here ? T. -- https://mail.python.org/mailman/listinfo/python-list

Re: 1 0 == True - False

2014-01-30 Thread Thomas Mlynarczyk
Thibault Langlois schrieb: 1 0 == True False What am I missing here ? This, perhaps: http://www.primozic.net/nl/chaining-comparison-operators-in-python/ Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche) -- https://mail.python.org/mailman

Re: 1 0 == True - False

2014-01-30 Thread Jussi Piitulainen
Thibault Langlois writes: Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type help, copyright, credits or license for more information. 1 0 == True False (1 0) == True True 1 (0 == True) True What am I missing here ? One or both

Re: 1 0 == True - False

2014-01-30 Thread Peter Otten
Jussi Piitulainen wrote: Thibault Langlois writes: Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type help, copyright, credits or license for more information. 1 0 == True False (1 0) == True True 1 (0 == True) True What am I

Re: 1 0 == True - False

2014-01-30 Thread Jussi Piitulainen
Peter Otten writes: Jussi Piitulainen wrote: Thibault Langlois writes: Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type help, copyright, credits or license for more information. 1 0 == True False (1 0) == True True 1 (0

Re:1 0 == True - False

2014-01-30 Thread Dave Angel
Thibault Langlois thibault.langl...@gmail.com Wrote in message: Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type help, copyright, credits or license for more information. 1 0 == True False (1 0) == True True 1 (0 == True) True What am I

Re: 1 0 == True - False

2014-01-30 Thread Thibault Langlois
information. 1 0 == True False (1 0) == True True 1 (0 == True) True What am I missing here ? T. You tell us. You supply only half the question, what it does, without saying what you expected or needed. I expect you're either confused

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 12:40 AM, Thibault Langlois thibault.langl...@gmail.com wrote: The recommendations to student are 1) do not assume True == 1 and do not use operator chaining. Not do not use, but do not misuse. Python's operator chaining is awesome for bounds checking: if 3 x 20:

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
In article 3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com, Thibault Langlois thibault.langl...@gmail.com wrote: You are right. I should have given some context. I am looking at this from the perspective of the teacher that has to explain idiosyncrasies of the language to inexperienced

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith r...@panix.com wrote: Better than that, do what I do. 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. Or: 1a) Assume that you don't have the full operator precedence table memorized and

Re: 1 0 == True - False

2014-01-30 Thread Devin Jeanpierre
On Thu, Jan 30, 2014 at 6:08 AM, Roy Smith r...@panix.com wrote: 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. 2) In cases where the expression is so simple, you couldn't possibly be wrong, see rule #1. Also, assume you don't

Re: 1 0 == True - False

2014-01-30 Thread Thibault Langlois
On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: In article 3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com, Thibault Langlois thibault.langl...@gmail.com wrote: You are right. I should have given some context. I am looking at this from the perspective of the

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
In article mailman.6143.1391091519.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith r...@panix.com wrote: Better than that, do what I do. 1) Assume that you don't have the full operator precedence table memorized and just

Re: 1 0 == True - False

2014-01-30 Thread Jussi Piitulainen
Roy Smith writes: In article 3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com, Thibault Langlois wrote: You are right. I should have given some context. I am looking at this from the perspective of the teacher that has to explain idiosyncrasies of the language to inexperienced

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 1:49 AM, Roy Smith r...@panix.com wrote: In article mailman.6143.1391091519.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith r...@panix.com wrote: Better than that, do what I do. 1) Assume that you

Re: 1 0 == True - False

2014-01-30 Thread Steven D'Aprano
On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. Oh really? Do you actually write stuff like this? b = ((2*a) + 1) if (b = (-1)): ... I would hope not. 2) In cases where

Re: 1 0 == True - False

2014-01-30 Thread Rustom Mody
On Thursday, January 30, 2014 8:39:03 PM UTC+5:30, Steven D'Aprano wrote: On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. Oh really? Do you actually write stuff like this? b

Re: 1 0 == True - False

2014-01-30 Thread Mark Lawrence
On 30/01/2014 14:46, Thibault Langlois wrote: On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: In article 3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com, Thibault Langlois thibault.langl...@gmail.com wrote: You are right. I should have given some context. I am

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: There's nothing to parenthesize in x = y z = w Hmm x = y z = w File stdin, line 1 SyntaxError: can't assign to comparison I don't think any number of parentheses will help that :-) --

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. Oh really? Do you actually write stuff like this? b

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: E.g. `x+1 0 and y = 5` is potentially as many as 9 distinct items to keep in short-term memory. But bracketing some terms as in `(x+1 0) and (y = 5)` can reduce that down to as few as two items. Yes,

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith r...@panix.com wrote: On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: E.g. `x+1 0 and y = 5` is potentially as many as 9 distinct items to keep in short-term memory. But bracketing some terms as in `(x+1 0) and

Re: 1 0 == True - False

2014-01-30 Thread Rotwang
On 30/01/2014 12:49, Dave Angel wrote: [...] For hysterical reasons, True and False are instances of class bool, which is derived from int. So for comparison purposes False==0 and True==1. But in my opinion, you should never take advantage of this, except when entering obfuscation

Re: 1 0 == True - False

2014-01-30 Thread Ethan Furman
On 01/30/2014 11:03 AM, Chris Angelico wrote: On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: Yes, that's probably how I would write that, although, this is even simpler: (x -1) and (y = 5) Be careful; that's not the same thing. How so? -- ~Ethan~ --

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
Fri, Jan 31, 2014 at 6:22 AM, Ethan Furman et...@stoneleaf.us wrote: On 01/30/2014 11:03 AM, Chris Angelico wrote: On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: Yes, that's probably how I would write that, although, this is even simpler: (x -1) and (y = 5) Be careful; that's not

Re: 1 0 == True - False

2014-01-30 Thread Dave Angel
Rotwang sg...@hotmail.co.uk Wrote in message: On 30/01/2014 12:49, Dave Angel wrote: [...] For hysterical reasons, True and False are instances of class bool, which is derived from int. So for comparison purposes False==0 and True==1. But in my opinion, you should never take

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:08 AM, Dave Angel da...@davea.name wrote: 'You have scored %i point%s' % (score, 's'*(score != 1)) Here I'd probably do something like 'You have scored {} {}' .format (score, 'point' if score==1 else 'points') Bah, what's the fun in that? 'You have scored %i

Re: 1 0 == True - False

2014-01-30 Thread Jussi Piitulainen
Roy Smith writes: On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: There's nothing to parenthesize in x = y z = w Hmm x = y z = w File stdin, line 1 SyntaxError: can't assign to comparison I don't think any number of parentheses will help that :-)

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:14 AM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: I don't think any number of parentheses will help that :-) Er, sorry about that. Here: x = y z == w Traceback (most recent call last): File stdin, line 1, in module NameError: name 'x' is not defined

Re: 1 0 == True - False

2014-01-30 Thread Ian Kelly
On Thu, Jan 30, 2014 at 1:08 PM, Dave Angel da...@davea.name wrote: Rotwang sg...@hotmail.co.uk Wrote in message: Really? I take advantage of it quite a lot. For example, I do things like this: 'You have scored %i point%s' % (score, 's'*(score != 1)) I also did that kind of thing when

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly ian.g.ke...@gmail.com wrote: Of course if you're at all concerned about i18n then the proper way to do it would be: ngettext(You have scored %d point, You have scored %d points, score) % score Ugh, so much duplication! We can totally do better than

Re: 1 0 == True - False

2014-01-30 Thread Ian Kelly
On Jan 30, 2014 1:40 PM, Chris Angelico ros...@gmail.com wrote: On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly ian.g.ke...@gmail.com wrote: Of course if you're at all concerned about i18n then the proper way to do it would be: ngettext(You have scored %d point, You have scored %d points,

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 8:17 AM, Ian Kelly ian.g.ke...@gmail.com wrote: Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only? Lack of a convincing use case, and the position of the following

Re: 1 0 == True - False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: `(x+1 0) and (y = 5)` Me: this is even simpler: (x -1) and (y = 5) On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: Be careful; that's not the same thing. In what way? I'm assuming x is some

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 9:09 AM, Roy Smith r...@panix.com wrote: On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: `(x+1 0) and (y = 5)` Me: this is even simpler: (x -1) and (y = 5) On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: Be careful;

Re: 1 0 == True - False

2014-01-30 Thread Joshua Landau
On 30 January 2014 20:38, Chris Angelico ros...@gmail.com wrote: Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only? You're not the first person to ask that:

Re: 1 0 == True - False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 10:36 AM, Joshua Landau jos...@landau.ws wrote: On 30 January 2014 20:38, Chris Angelico ros...@gmail.com wrote: Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only?

Re: 1 0 == True - False

2014-01-30 Thread Rotwang
On 30/01/2014 23:36, Joshua Landau wrote: On 30 January 2014 20:38, Chris Angelico ros...@gmail.com wrote: Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only? You're not the first person

Removal of iterable unpacking in function calls (was: 1 0 == True - False)

2014-01-30 Thread Ben Finney
Rotwang sg...@hotmail.co.uk writes: On a vaguely-related note, does anyone know why iterable unpacking in calls was removed in Python 3? This is explained in the PEP which described its removal URL:http://www.python.org/dev/peps/pep-3113/, especially

Re: 1 0 == True - False

2014-01-30 Thread Joshua Landau
On 31 January 2014 00:10, Rotwang sg...@hotmail.co.uk wrote: On a vaguely-related note, does anyone know why iterable unpacking in calls was removed in Python 3? I mean things like def f(x, (y, z)): return (x, y), z I don't have a use case in mind, I was just wondering.

Re: 1 0 == True - False

2014-01-30 Thread Rustom Mody
On Friday, January 31, 2014 12:23:42 AM UTC+5:30, Roy Smith wrote: On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: 1) Assume that you don't have the full operator precedence table memorized and just parenthesize