t472.py 739 B

12345678910111213141516
  1. def helper(got,expect):
  2. if got == expect: print True
  3. else: print False, expect, got
  4. print "\nstr.replace"
  5. helper('hello'.replace('l','L'),'heLLo')
  6. helper('hello'.replace('l','L',1),'heLlo')
  7. helper('hello'.replace('l','L',5),'heLLo')
  8. helper('hello'.replace('l','L',0),'hello')
  9. helper('hello hello hello'.replace('ll','lll'),'helllo helllo helllo')
  10. helper('hello hello hello'.replace('ll','lll',2),'helllo helllo hello')
  11. helper('hello hello hello'.replace('ll','l'),'helo helo helo')
  12. helper('hello hello hello'.replace('ll','l',2),'helo helo hello')
  13. helper('abcabcaaaabc'.replace('abc','123'),'123123aaa123')
  14. helper('abcabcaaaabc'.replace('abc','123',2),'123123aaaabc')
  15. helper('abcabcaaaabc'.replace('abc','123',-1),'123123aaa123')