在如下代码中return ' '.join(s.split()[::-1]) if s.strip() != "" else s为什么if s.strip() != "" else s写在return之后,照样可以判断这条Python语句工作过程是怎么样的,尤其是return语句与分支语句的关系
业精于勤,荒于嬉;行成于思,毁于随。
In fact, it is the ternary operator in other languages
if s.strip() !== "": return ' '.join(s.split()[::-1]) else: return s
Return is followed by a whole. The boss above made it very clear, it’s the ternary operator
' '.join(s.split()[::-1]) if s.strip() != "" else s # 简化版 A if X else B
If X is True, then the overall value is A, otherwise it is B
This is how the ternary operator is written in other languages
X ? A : B;
In fact, it is the ternary operator in other languages
Return is followed by a whole. The boss above made it very clear, it’s the ternary operator
If X is True, then the overall value is A, otherwise it is B
This is how the ternary operator is written in other languages