title: How to replace an empty string with 0, but leave it alone if not empty
body: <p>Python's behavior seems inconsistent when replacing values in the case shown below (using python 3.6.5)</p>
  
  <pre><code>    &gt;&gt;&gt; emptyString = '    '
      &gt;&gt;&gt; emptyString.strip().replace('','0') #produces expected results
      '0'
      &gt;&gt;&gt; notEmptyString = ' 50 '
      &gt;&gt;&gt; notEmptyString.strip().replace('','0') #expected '50'
      '05000'
      &gt;&gt;&gt; shortString = notEmptyString.strip()
      &gt;&gt;&gt; shortString  #results as expected
      '50'
      &gt;&gt;&gt; shortString.replace('','0') #unexpected results - expected '50'
      '05000'
  </code></pre>
  
  <p>This is what I'd like to see:</p>
  
  <blockquote>
    <ul>
    <li>if string has a value, just strip() the leading and trailing spaces.</li>
    <li>if string is empty (i.e. "") or string is just blank characters (i.e. "    ") then strip it to be "" and replace "" with '0'</li>
    </ul>
    
    <p>Example #1...  string  = " 10 "....  then just strip leading and
    trailing spaces<br>
    Example #2...  string  = '   ' .... then convert to
    '0'</p>
  </blockquote>
  
  <p>I can get the results I want by other means, but I wondered if anybody understands why python produces these results.</p>