Learing Python, Newbie question
Michael Abbott
michael at rcp.co.uk
Thu Oct 25 06:39:13 EDT 2001
Johannes Gamperl <info at devshare.de> wrote in
news:MPG.1642065dc9ef9d80989687 at news.t-online.de:
> Do you know if there is a
> coditional operator in python ( ?: )
>
> e.g.
>
> if os.path.exists("gbook.txt"):
> db_first = 0;
> else:
> db_first = 1;
>
>
> db_first = ( os.path.exists("gbook.txt") ) ? 0:1;
Ho ho!
I'm glad that beginners also miss the conditional operator.
I'm afraid there's been a bit of an argument about possible syntax, and
most of the old hands seem firmly convinced that the conditional operator
serves no useful purpose.
No, it doesn't exist!
Mind you, in the example you give, there's no point at all in having a
conditional operator, since what you *really* wanted to write is:
db_first = not os.path.exists("gbook.txt")
More information about the Python-list
mailing list