title: Refactoring "x if x is not None else y" to "x or y"
body: <p>I came across to a piece of Python Code which technically looks like this:</p>
  
  <pre><code>def bar(b):
      return b*2
  
  class MyClass(object):
      def __init__(self, a):
          self.a = a
          self.b = 10
  
      def foo(self, b=None):
          return bar(b if b is not None else self.b)
  </code></pre>
  
  <p>So the class has <code>b</code> as a fixed attribute, which is used as default input for a classmethod <code>foo</code>, if it is called without argument. </p>
  
  <p>Please assume that <code>b</code> in this case is expected to be a float.</p>
  
  <p>Please ignore unused <code>self.a</code>, it is used otherwise - i just wanted to make sure that you see that there are attributes settable by the constructor. </p>
  
  <p>The usage would look like this:</p>
  
  <pre><code>c = MyClass(2)
  c.foo(3)  # returns 3*2 = 6
  c.foo()  # returns 10*2 = 20
  </code></pre>
  
  <p>In this case, I was wondering about the <code>foo</code>-method. Is this a good way to implement <code>self.b</code> as default value for <code>b</code>?</p>
  
  <p>Is one of the following two suggestions by me more or less desireable? If so: why?</p>
  
  <pre><code>def foo(self, b=None):
      return bar(b or self.b)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>def foo(self, b=self.b):
      return bar(b)
  </code></pre>