“operador ternario Python” Código de respuesta

Operador ternario en Python

a, b = 10, 20
# Copy value of a in min if a < b else copy b 
min = a if a < b else b 
Delightful Dunlin

operador ternario Python

value_if_true if condition else value_if_false
Thankful Tamarin

Ejemplo de operador ternario en Python

Program to demonstrate ternary operators in Python
marks = input('Enter the marks: ')
print("The result is Pass" if int(marks)>=35 else "The result is Fail")
Gorgeous Gazelle

¿Cuál es el operador ternario en Python?

condition = True
print("This condition is true!") if condition else print("This condition is false!")
# The if statement in one line! (Ternary operator)
Cheerful Cassowary

Python Turnary

(if_test_is_false, if_test_is_true)[test]
Ugly Unicorn

Python Ternary

a = 1
b = 2

1 if a > b else -1 
# Output is -1

1 if a > b else -1 if a < b else 0
# Output is -1
Piri Roter

Respuestas similares a “operador ternario Python”

Preguntas similares a “operador ternario Python”

Más respuestas relacionadas con “operador ternario Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código