这是一种古老的习语;插入括号以显示优先级,
(port == "443" and "https://") or "http://"
x and y返回
y是否
x为真,
x如果
x为假;
a or b反之亦然,
a如果是空的,则返回,否则返回
b。
因此,如果
port == "443"为true,则返回的RHS
and,即
"https://"。否则,该元素
and为false,因此
or起作用并返回 其 RHS “ http://” 。
在现代Python中,翻译这种古老习语的更好方法是:
"https://" if port == "443" else "http://"



