0
点赞
收藏
分享

微信扫一扫

在 Python 中,​​?:​​​ 符号并不是一个有效的运算符。这个符号在其他一些编程语言中,如 JavaScript 或 C,被称为条件(三元)运算符

在 Python 中,?: 符号并不是一个有效的运算符。这个符号在其他一些编程语言中,如 JavaScript 或 C,被称为条件(三元)运算符。然而,在 Python 中,我们使用 if-else 表达式来达到相同的目的。例如:

x = 10
y = 20
print("x is greater") if x > y else print("y is greater")

在上述代码中,如果 x > y 为真,则输出 "x is greater",否则输出 "y is greater"。这与其他语言中的 ?: 运算符有相同的效果。¹²。希望这个答案对你有所帮助!源: 与必应的对话, 2023/12/26

(1) Python 运算符 | 菜鸟教程. https://www.runoob.com/python/python-operators.html.

(2) python中的各种符号(欢迎补充)_python符号大全-CSDN博客. https://blog.csdn.net/weixin_38981172/article/details/90176525.

(3) Python中%是什么意思?如何使用? - 知乎. https://www.zhihu.com/question/54933434.

(4) Python 不等于操作符教程 - freeCodeCamp.org. https://www.freecodecamp.org/chinese/news/python-not-equal-how-to-use-the-does-not-equal-operator/.

(5) Python 转义字符 & 格式化表达式 - 知乎. https://zhuanlan.zhihu.com/p/655970361.

举报

相关推荐

0 条评论