Learing Python, Newbie question
michael at rcp.co.uk
Thu Oct 25 12:39:13 CEST 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 ( ?: )
> if os.path.exists("gbook.txt"):
> db_first = 0;
> db_first = 1;
> db_first = ( os.path.exists("gbook.txt") ) ? 0:1;
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