SHARE
TWEET

Untitled

a guest Jun 16th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >>> a = 100
  2. >>> b = True
  3. >>> print a if b
  4.   File "<stdin>", line 1
  5.     print a if b
  6.              ^
  7. SyntaxError: invalid syntax
  8.      
  9. if condition: statement
  10. if condition:
  11.     block
  12.      
  13. expression_if_true if condition else expression_if_false
  14.      
  15. print a if b else 0
  16.      
  17. print (a if b else 0)
  18.      
  19. x = a if b else 0
  20.      
  21. x = (a if b else 0)
  22.      
  23. a = 1 if b else 0
  24.      
  25. a = 1 if b else a
  26.      
  27. >>> b = True
  28. >>> a = 1 if b else None
  29. >>> a
  30. 1
  31. >>> b = False
  32. >>> a = 1 if b else None
  33. >>> a
  34. >>>
  35.      
  36. >>> if b: print(a)
  37.      
  38. a = 100
  39. b = True
  40. print a if b else "",  # Note the comma!
  41. print "see no new line"
  42.      
  43. 100 see no new line
  44.      
  45. from __future__ import print_function
  46. a = False
  47. b = 100
  48. print(b if a else "", end = "")
  49.      
  50. if logging: print data
  51.      
  52. [on_true] if [expression] else [on_false]
  53.      
  54. print a if b else ''
  55.      
  56. print (1==2 and "only if condition true" or "in case condition is false")
  57.      
  58. print 1==2 and "aa" or ((2==3) and "bb" or "cc")
  59.      
  60. >>> print "%d item%s found." % (count, (count>1 and 's' or ''))
  61. 1 item found.
  62. >>> count = 2
  63. >>> print "%d item%s found." % (count, (count>1 and 's' or ''))
  64. 2 items found.
  65.      
  66. a=100
  67. b=True
  68.  
  69. if b:
  70.    print a
  71.      
  72. print '%s' % (a if b else "")
  73.      
  74. print '{}'.format(a if b else "")
  75.      
  76. print(f'{a if b else ""}')
  77.      
  78. a = b or 0
  79.      
  80. b = True
  81.      
  82. b or 0
  83.      
  84. True
  85.      
  86. if b:
  87.    print a
  88.      
  89. a = 1 if b else 0
  90.      
  91. if b:
  92.     print a
  93. else:
  94.     print 'b is false'
  95.      
  96. print([a for i in range(0,1) if b])
  97.      
  98. print([a for a in range(a,a+1) if b])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top