Nifty, little one-liner I learned today. Instead of doing this:

def func(foo):
    if foo == 0:
        return "bar"
    else:
        return "baz"

You can simply do this:

def func(foo):
    return "bar" if foo == 0 else "baz"


Pretty cool for those who didn't know. ;-)

- Karan Goel
3

View comments

Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.