t469.py 591 B

1234567891011121314151617181920212223242526
  1. def helper(got,expect):
  2. if got == expect: print True
  3. else: print False, expect, got
  4. print "\nstr.ljust"
  5. helper('12345'.ljust(8),'12345 ')
  6. helper('12345'.ljust(8,'.'),'12345...')
  7. print "\nstr.center"
  8. helper('12345'.center(7),' 12345 ')
  9. helper('12345'.center(8,'.'),'.12345..')
  10. print "\nstr.rjust"
  11. helper('12345'.rjust(8),' 12345')
  12. helper('12345'.rjust(8,'.'),'...12345')
  13. def helper(str,fillchar):
  14. print
  15. print str.ljust(10,fillchar)
  16. print str.center(10,fillchar)
  17. print str.rjust(10,fillchar)
  18. helper('a','-')
  19. helper('?','!')
  20. helper('-','.')
  21. helper('hello','~')