News for hackers. Stuff that matters.
Re:The Zen of Python by Example by rikthevik on Thursday February 10, 2011 @06:05PM (#2204261)
Yeah, I don't think you can use i % 2 as an equivalent of i % 2 == 0. Maybe it's a python 3 thing, but on my 2.6.1 the mod operator just returns the remainder, it doesn't change its output if it's a boolean context (which would be perlish and highly unpythonic).

I think i % 2 is just straight up incorrect.

If we're talking about style, I think i % 2 == 0 is much more clear than (not i % 2). It says explicitly that the remainder of i divided by 2 is 0.

Re:The Zen of Python by Example by eru on Friday February 11, 2011 @06:31AM (#2205958)
> Yeah, I don't think you can use i % 2 as an equivalent of i % 2 == 0. Maybe it's a python 3 thing, but on my 2.6.1 the mod operator just returns the remainder, it doesn't change its output if it's a boolean context (which would be perlish and highly unpythonic).

    $ python3
    >>> not 0
    True
Python doesn't have Perl-like contexts, but it does treat lots of values as True or False. I do agree that

    i % 2 == 0
is more explicit here.