"John Pote" wrote in message
news:e0a8e1bc-6e03-e42b-d6e8-d690e2d5a...@jptechnical.co.uk...
I interpret the above comparison as
>>> bool([1,2,3]) == bool(True)
True
>>>
A tiny addition to what has already been said.
As True is by definition a boolean, you can write this as
bool([1, 2,
Chris Angelico writes:
> Or you could say "not [1,2,3] == not True",
> but that's a bit less clear
It's less clear in more ways than one:
3.6> not [1,2,3] == not True
File "", line 1
not [1,2,3] == not True
^
SyntaxError: invalid syntax
3.6> not
On Sat, Nov 24, 2018 at 11:28 AM John Pote wrote:
> But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box)
>
> >>> if []: print("Truthy")
> ...
> >>> if [1,2,3]: print("Truthy")
> ...
> Truthy
> >>>
>
> from which I concluded [] is Falsey and [1,2,3] is Truthy and the abov
On 21/11/2018 19:18, Python wrote:
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
1 in [1,2,3] == True
False
1 in ([1,2,3] == True)
Traceback (most recent call last):
File "", line
On 2018-11-22 09:58, Chris Angelico wrote:
> On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote:
>>
>> On 21/11/2018 20:18, Python wrote:
>>> $ python3
>>> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
>>> [GCC 5.4.0 20160609] on linux
>>> Type "help", "copyright", "credits" or "license" for mor
On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote:
>
> On 21/11/2018 20:18, Python wrote:
> > $ python3
> > Python 3.5.2 (default, Nov 23 2017, 16:37:01)
> > [GCC 5.4.0 20160609] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
> 1 in [1,2,3] == True
> >
On 21/11/2018 20:18, Python wrote:
> $ python3
> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
1 in [1,2,3] == True
> False
1 in ([1,2,3] == True)
> Traceback (most recent call last):
On 11/21/18 7:09 PM, Chris Angelico wrote:
> On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers
> <2qdxy4rzwzuui...@potatochowder.com> wrote:
>> But the second one has to do an expensive subset operation. If I think
>> "is elem in both sets," then I'd never write:
>>
>> (elem in set1) and (set1 <
On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers
<2qdxy4rzwzuui...@potatochowder.com> wrote:
> But the second one has to do an expensive subset operation. If I think
> "is elem in both sets," then I'd never write:
>
> (elem in set1) and (set1 <= set2)
Yes, but that doesn't mean "is elem in both
On 11/21/18 6:45 PM, Ian Kelly wrote:
> On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka
wrote:
>>
>> 21.11.18 22:17, Cameron Simpson пише:
>>> Can someone show me a real world, or failing that - sane looking,
>>> chained comparison using "in"?
>>
>> s[0] == s[-1] in '\'"'
>>
>> Tests tha
Serhiy,
On 22/11/18 10:50, Serhiy Storchaka wrote:
21.11.18 22:17, Cameron Simpson пише:
Can someone show me a real world, or failing that - sane looking,
chained comparison using "in"?
s[0] == s[-1] in '\'"'
Tests that string s starts and ends with a single or double quote.
Am admir
On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote:
>
> 21.11.18 22:17, Cameron Simpson пише:
> > Can someone show me a real world, or failing that - sane looking,
> > chained comparison using "in"?
>
> s[0] == s[-1] in '\'"'
>
> Tests that string s starts and ends with a single or double
21.11.18 22:17, Cameron Simpson пише:
Can someone show me a real world, or failing that - sane looking,
chained comparison using "in"?
s[0] == s[-1] in '\'"'
Tests that string s starts and ends with a single or double quote.
It can be also used with sets:
elem in set1 <= set2
--
htt
On Thu, Nov 22, 2018 at 8:22 AM Python wrote:
>
> On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote:
> > > if item in list == item_should_be_in_list():
> > > # "good" state, i.e. is true if item is in list and should be, or
> > > isn't and shouldn't.
> > > ...
> >
> > If I
On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote:
> > if item in list == item_should_be_in_list():
> > # "good" state, i.e. is true if item is in list and should be, or isn't
> > and shouldn't.
> > ...
>
> If I saw this in _any_ language, I would want it to be parenthesize
On Thu, Nov 22, 2018 at 06:33:54AM +1100, Chris Angelico wrote:
> On Thu, Nov 22, 2018 at 6:23 AM Python wrote:
> > How is the first not equivalent to either one of the second or third?
> > My expectation is it should produce the same result as the second. It
> > *seems* like Python is ignoring t
On Thu, Nov 22, 2018 at 7:47 AM Python wrote:
>
> On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote:
> > On 21Nov2018 19:40, MRAB wrote:
> > >On 2018-11-21 19:18, Python wrote:
> > >1 in [1,2,3] == True
> > >>False
> > >>
> > >It's a chained comparison. It applies to '<', '<=',
On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote:
> On 21Nov2018 19:40, MRAB wrote:
> >On 2018-11-21 19:18, Python wrote:
> >1 in [1,2,3] == True
> >>False
> >>
> >It's a chained comparison. It applies to '<', '<=', '>', '>=',
> >'==' and '!=', but also to 'in', although I've ne
On 21Nov2018 19:40, MRAB wrote:
On 2018-11-21 19:18, Python wrote:
1 in [1,2,3] == True
False
It's a chained comparison. It applies to '<', '<=', '>', '>=', '=='
and '!=', but also to 'in', although I've never seen a chained
comparison using 'in' in practice.
Me either. In fact, I was as
On 2018-11-21 19:18, Python wrote:
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
1 in [1,2,3] == True
False
1 in ([1,2,3] == True)
Traceback (most recent call last):
File "", line
On Thu, Nov 22, 2018 at 6:33 AM Python wrote:
> FWIW I meant my expectation is it should be the same as #3 (I confused
> the 2nd item with the second subsequent thing that it did not match)
> since "in" and "==" have the same precedence, and should be evaluated
> in order left to right. IOW, it s
On Thu, Nov 22, 2018 at 6:23 AM Python wrote:
>
> $ python3
> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 1 in [1,2,3] == True
> False
> >>> 1 in ([1,2,3] == True)
> Traceback (most rec
On Wed, Nov 21, 2018 at 01:18:22PM -0600, Python wrote:
> $ python3
> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 1 in [1,2,3] == True
> False
> >>> 1 in ([1,2,3] == True)
> Traceback (
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 in [1,2,3] == True
False
>>> 1 in ([1,2,3] == True)
Traceback (most recent call last):
File "", line 1, in
TypeError: argument of ty
24 matches
Mail list logo