Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

Thread Tools

Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

Steven Bethard
Posts: n/a
Kristian Domke wrote:
> I am trying to learn python at the moment studying an example program
> ( from the twisted framework, if you want to know)
> There I found a line
> foo = (not f and 1) or 0

Equivalent to ``foo = int(not f)``

> In this case f may be None or a string.
> If I am not wrong here, one could simply write
> foo = not f

No cast to int() here.

Reply With Quote
George Sakkis
Posts: n/a
On Jan 23, 4:06 am, Gary Herron <(E-Mail Removed)> wrote:

> However there *is* a (subtle) difference between
> not f
> and
> (not f and 1) or 0
> The first produces a boolean value, and the second produces an int
> value, but since one is a subclass of the other, you'd have to write
> quite perverse code care about the difference.

Even if for some reason I did want the result to be int, I would write
it as "int(not f)".

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why class A and E's sizes are 4 instead of 1? C++ 3 08-25-2006 07:32 AM
Why not FILE instead of FILE*? Joona I Palaste C Programming 12 04-20-2004 11:41 PM