Guest User

Untitled

a guest
Jun 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. >>> ' Hello '.strip()
  2. 'Hello'
  3. >>> ' Hello'.strip()
  4. 'Hello'
  5. >>> 'Bob has a cat'.strip()
  6. 'Bob has a cat'
  7. >>> ' Hello '.strip() # ALL spaces at ends removed
  8. 'Hello'
  9.  
  10. def strip_one_space(s):
  11. if s.endswith(" "): s = s[:-1]
  12. if s.startswith(" "): s = s[1:]
  13. return s
  14.  
  15. >>> strip_one_space(" Hello ")
  16. ' Hello'
  17.  
  18. >>> " Hellon".strip(" ")
  19. 'Hellon'
  20.  
  21. myString.strip()
  22.  
  23. myString.strip()
  24.  
  25. myphrases = [ " Hello ", " Hello", "Hello ", "Bob has a cat" ]
  26.  
  27. for phrase in myphrases:
  28. print phrase.strip()
Add Comment
Please, Sign In to add comment