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

前端 未结 7 1721
后悔当初
后悔当初 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:19

    and returns the right operand if the left is true. or returns the right operand if the left is false. Otherwise they both return the left operand. They are said to coalesce.

提交回复
热议问题