Python06 of branching and looping (ternary operator)

Python order to make the process more simple and newly introduced over a ternary operator, by definition is to have three parameters.

  Format: X IF condition tables expression else y

    First determination condition expression true and false, true then take the x value, take or y values.

    For example: 3 IF 4> 3 the else 4 is 3 , and 3 4 IF <3 the else 4 value of 4

z = "x smaller than y" if x <y else " x is greater than Y" 
Z 
'X is less than y' 
z = "x smaller than y" if x> y else " x is greater than Y" 
Z 
'X is greater than y'

  

Guess you like

Origin www.cnblogs.com/ksht-wdyx/p/11304116.html