How do “and” and “or” work when combined in one statement?

前端 未结 7 1710
后悔当初
后悔当初 2020-12-03 11:44

For some reason this function confused me:

def protocol(port):
    return port == \"443\" and \"https://\" or \"http://\"

Can somebody expl

7条回答
  •  天命终不由人
    2020-12-03 12:17

    You may want to read up on the "and / or trick" of Python in this article The Peculiar Nature of And and Or in Python. It's a bit like the IIF() in VBA or VB, or ?: in C-style languages.

提交回复
热议问题