我们可以在 Python 中链接三元运算符吗? [英] Can we chain the ternary operator in Python?

查看:20
本文介绍了我们可以在 Python 中链接三元运算符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在 Python 中链接三元运算符吗?我们可以为 Java 中的多个 if 条件执行此操作.这也可以用 Python 完成吗?

Can we chain the ternary operator in Python? We can do it for multiple if conditions in Java. Can that be done in Python too?

推荐答案

是.

x = 'x' if 1<0 else 'y' if 0<1 else 'z'

这篇关于我们可以在 Python 中链接三元运算符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆