This is an old idiom; insert parentheses to display priority,
(port == "443" and "https://") or "http://"
x and y returns y if x is true, x if x is false; a or b , on the contrary, returns a if it is right, otherwise b .
So, if port == "443" true, this returns RHS and , i.e. "https://" . Otherwise, and is false, so or goes into the game and returns `` http: // '', its RHS.
In modern Python, the best way to translate this old idiom is:
"https://" if port == "443" else "http://"
source share