Can I use a conditional in a variable declaration?
bencvt at gmail.com
Sun Mar 19 05:25:59 CET 2006
volcs0 at gmail.com wrote:
> I've done this in Scheme, but I'm not sure I can in Python.
> I want the equivalent of this:
> if a == "yes":
> answer = "go ahead"
> answer = "stop"
> in this more compact form:
> a = (if a == "yes": "go ahead": "stop")
> is there such a form in Python? I tried playing around with lambda
> expressions, but I couldn't quite get it to work right.
There will be, in Python 2.5 (final release scheduled for August 2006):
>>> answer = "go ahead" if a=="yes" else "stop"
More information about the Python-list