Ternary operation

From Free net encyclopedia

(Redirected from Ternary operator)

In mathematics, a ternary operation is any operation of arity three, that is, that takes three arguments. A ternary operator (sometimes inaccurately referred to as a tertiary operator) is an operator that takes three arguments.

Many programming languages that use C-like syntax feature a ternary operator, ?:; unqualified, "ternary operator" usually refers to this. The ?: operator is used as a shorthand replacement for the if-then-else conditional statement; the general form is condition ? op1 : op2. If condition is true, the statement evaluates as op1; otherwise, it evaluates as op2.

Though it has been delayed for several years by disagreements over syntax, a ternary operator for Python has been approved as PEP 308 and will be added to the upcoming 2.5 release.

External links


et:Ternaarne tehe