Question from a python newbie

Russell rcooknet at gmail.com
Thu Dec 13 10:39:30 EST 2007


I've been learning Python slowly for a few months, coming from a C/C+
+, C#, Java, PHP background.  I ran across a code fragment I'm having
trouble wrapping my brain around.  I've searched the Language
Reference and was not able to find any info regarding the structure of
this code fragment:

int(text) if text.isdigit() else text

It is part of a larger lambda statement.  I do get the lambda
declaration, but having trouble with what is happening in that
fragment.  Here is the full lambda statement:

convert = lambda text: int(text) if text.isdigit() else text

Thanks for any help you can provide explaining this to me.



More information about the Python-list mailing list