result=值1 if 条件 else 值2

如果条件为真,result=值1

如果条件为假,result=值2

例子:

1 a,b,c=1,3,5
2 d=a if a>b else c
3 print(d)  #d的值为5

 

相关文章:

  • 2021-07-18
  • 2021-10-13
  • 2021-10-03
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2021-12-18
  • 2021-10-23
  • 2022-02-05
  • 2022-12-23
  • 2021-08-10
相关资源
相似解决方案