Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 11th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # -*- encoding: utf-8 -*-
  2. """
  3. Использование логических операций
  4. """
  5.  
  6. t, f = 1, 0
  7. x, y = 88, 99
  8.  
  9. a = (t and x) or y           # if true, x
  10. print a
  11.  
  12. a = (f and x) or y           # if false, y
  13. print a
  14.  
  15. print ((t and [x]) or [y])[0]     # if true, x
  16.  
  17. print ((f and [x]) or [y])[0]     # if false, y
  18.  
  19. print (t and f) or y              # fails: f is false, skipped
  20.  
  21. print ((t and [f]) or [y])[0]     # works: f returned anyhow