这里有一个简单的对象创建和赋值,使用Java中的一行三值表达式。
Interval newInterval = previous.end <= current.end ? new Interval(previous.start, current.end : new Interval(previous.start, previous.end)
python的等价物是,
new_interval = Interval(previous.start, current.end) if previous.end <= current.end else Interval(previous.start, previous.end)
?
最佳答案
The form I'd like more is probably
new_interval = Interval(previous.start, max(current.end, previous.end))
关于python - Python三元表达式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45178451/