Ternary operation
From Wikipedia, the free encyclopedia
In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. An example of a ternary operation is the product in a heap.
In computer science a ternary operator (sometimes incorrectly referred to as a tertiary operator) is an operator that takes three arguments. The arguments and result can be of different types.
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 had been delayed for several years by disagreements over syntax, a ternary operator for Python was approved as PEP 308 and was added to the 2.5 release in September 2006.
[edit] External links
- Description of Ternary Conditional Expression in Python (PEP 308)
- Description in the Java Language Specification
- Description in the PHP Language Documentation