if-else statement

Duncan Booth duncan.booth at invalid.invalid
Sat Jan 10 09:26:15 EST 2009


Gandalf <goldnery at gmail.com> wrote:

> other languages like PHP or javascript  as this if-else operator like
> this
> 
> myVar = checking  == 1? 'string': 'other string'
> 
> is this stuff exist in python?
> 
See http://docs.python.org/reference/expressions.html#boolean-operations

conditional_expression ::=  or_test ["if" or_test "else" expression]

...

The expression x if C else y first evaluates C (not x); if C is true, x is 
evaluated and its value is returned; otherwise, y is evaluated and its 
value is returned.



More information about the Python-list mailing list