[Tutor] iterators
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Jul 5 04:01:14 EDT 2016
On 05/07/16 01:42, Steven D'Aprano wrote:
> On Tue, Jul 05, 2016 at 12:47:27AM +0100, Alan Gauld via Tutor wrote:
>
>>> I then tried using
>>>
>>> elif keycode == 27:
>>>
>>> but this statement didn't work.
>>
>> I'm not sure why that didn't work.
>> What exactly happened? Did you get a different error message?
>> If so what?
>
> I expect that the keycode is always a tuple, usually with two items but
> sometimes with one. So keycode == 27 compares the tuple (27,) with the
> int 27 and finds them to be different.
but then the 'in' tests would fail.
>>> (27,) in (27,36)
False
the fact that the 'in' tests work suggests that keycode
is an int. But in that case the == test should work...
Although I just realized that the OP didn't actually say
the 'in' tests worked, just that they pass the compiler...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list