About 1,820,000 results
Open links in new tab
  1. Does Python have a ternary conditional operator?

    Dec 27, 2008 · Yes, Python has a ternary conditional operator, also known as the conditional expression or the ternary operator. The syntax of the ternary operator in Python is:

  2. Conditional/ternary operator for expressions in Python

    Many languages have a conditional (AKA ternary) operator. This allows you to make terse choices between two values based on a condition, which makes expressions, including assignments, …

  3. How to create ternary contour plot in Python? - Stack Overflow

    Apr 8, 2015 · It uses the library referenced before. These seem to be the best options for Python: Marc Harper's python-ternary Veusz, a Python plotting library There are also some suggestions in another …

  4. Python Ternary Operator Without else - Stack Overflow

    Aug 30, 2012 · Like any operator, it must return something, so how can you have a ternary operator without the else clause? What is it supposed to return if the condition isn't true-like?

  5. python - Putting an if-elif-else statement on one line? - Stack Overflow

    Dec 25, 2012 · Is there an easier way of writing an if-elif-else statement so it fits on one line? For example, if expression1: statement1 elif expression2: statement2 else: statement3 Or a real-world

  6. Python ternary operator - Stack Overflow

    Nov 5, 2010 · Python ternary operator [duplicate] Asked 15 years, 1 month ago Modified 2 years, 11 months ago Viewed 31k times

  7. Understanding Ternary Operator in Python - Stack Overflow

    Jul 31, 2023 · Python did not have the ternary operator at all for a long time, because it often results in confusing and difficult-to-read code. One originally had to write a > 5 and 'Greater' or 'Lesser', which …

  8. Em Python existe operação ternária? - Stack Overflow em Português

    Oct 26, 2016 · Em Python o if pode ser usado tanto como um statement, como um operador em contextos diferentes. Como operador dá para fazer assim: print(1 if True else 2) No seu exemplo: x = …

  9. syntax - Conditional operator in Python? - Stack Overflow

    That C++ operator is called the "conditional operator" or the "ternary operator".

  10. Does Python have ternary conditional with elif? - Stack Overflow

    Closed 8 years ago. I have recently found this question: Does Python have a ternary conditional operator? and discover something called ternary conditional a = b if c == d else e. My question: …