84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
在如下代码中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