开发者

Does Cython support the ternary style if statement (if ? then : else)?

开发者 https://www.devze.com 2023-01-30 05:51 出处:网络
I forget the technical term for the (if ? then : else) format in C/C++. Also, is this syntax supported in the Cython (a C variant of Python)?

I forget the technical term for the (if ? then : else) format in C/C++. Also, is this syntax supported in the Cython (a C variant of Python)?

I need to know the technical name so I can lookup if Cython supports this feature.

UPDA开发者_JS百科TE: Does anyone know if Cython supports this?

Solution: In cython/python this is written as (b if a else c) compare to (a ? b : c)


It's called the ternary conditional operator. It's often just called the ternary operator, but being ternary is not necessarily (but in practice usually is) unique to the conditional operator.

EDIT: In regards to whether Cython supports (x ? y : z), it appears not to based on some preliminary Googling. But Python (and theoretically Cython I think? Disclaimer: I don't use Cython) supports the same result (if/else expression) with (y if x else z). EDIT 2: The Cython documentation I've found says that it works the same as in regular Python.


It's often called the ternary operator, or inline if.


ternary operator.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号