Home  >  Article  >  Backend Development  >  Does the ternary operator exist in Python?

Does the ternary operator exist in Python?

silencement
silencementOriginal
2019-05-23 10:44:403642browse

Does the ternary operator exist in Python?

There are no ternary expressions in other languages ​​in python, but there are similar implementation methods.

For the following requirements

Does the ternary operator exist in Python?

1. The ternary expression in other languages ​​​​(such as java) is as follows

Does the ternary operator exist in Python?

2. There are only similar alternatives in python, which are slightly different from other languages, as follows

Does the ternary operator exist in Python?

You can also use a simple formula, as follows,

Does the ternary operator exist in Python?

The above is the detailed content of Does the ternary operator exist in Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn