由于某种原因,这个功能让我感到困惑:
def protocol(port):
return port == "443" and "https://" or "http://"
有人可以解释幕后发生的事情的顺序,以使其按原样工作。
在我尝试之前,我是这样理解的:
A)
def protocol(port):
if port == "443":
if bool("https://"):
return True
elif bool("http://"):
return True
return False
或 B)
def protocol(port):
if port == "443":
return True + "https://"
else:
return True + "http://"
这是 Python 中的某种特殊情况,还是我完全误解了语句的工作原理?