ternaryTernary operation implementation | |
Download |
ternary Ranking & Summary
Advertisement
- License:
- MIT/X Consortium Lic...
- Price:
- FREE
- Publisher Name:
- Wijnand Modderman
- Publisher web site:
- http://dev.tehmaze.com/
ternary Tags
ternary Description
Ternary operation implementation ternary is a simple hack using the slice operation to mimic C-style ternary operation:x = a ? b : cIn Python we would write:>>> x = a and b or cOr (rather than above, this is safe for returning Falsy values for b):>>> x = (a and or )Or:>>> x = b if a else cOr:>>> x = lambda i: (b, c)Or:>>> if a:... x = b... else:... x = cNow we can also write:>>> x = ternaryUsageUsing the slice operation:>>> value = ternary Requirements: · Python
ternary Related Software