• maegul (he/they)
    link
    fedilink
    English
    12
    edit-2
    1 year ago

    Python, checking in …

    return (a or b)
    

    Parentheses aren’t necessary, I just prefer them for readability.

    See python documentation on boolean operators for reference. Short story is a or b is an expression that evaluates to a if a is “truthy” else b. “Falsy” is empty strings/containers, 0 and None.

      • @Bumblefumble@lemm.ee
        link
        fedilink
        3
        edit-2
        1 year ago

        So this won’t do the intended thing if a is 0.

        Edit: Sorry I meant to reply to the parent comment, realising now you already write the exact same thing.

      • maegul (he/they)
        link
        fedilink
        English
        11 year ago

        That’s a shame, it would have been fitting in “modern” Python along with the walrus and static type system.