Advertisement
ganiyuisholaafeez

Strip and replace functions

Feb 19th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. """ This function strip a string and replace some characters with
  2. with another characters """
  3. # The function is named fancy_cleanup and it accepts one argument
  4. def fancy_cleanup(string):
  5.    
  6. # Stripping the string off unwanted whitespaces and also
  7. # replace "g" with "z" and " " with "!"    
  8.     cleanup = string.strip().replace("g", "z").replace(" ", "!")
  9.  
  10. # Returning the formatted string
  11.     return cleanup
  12.  
  13. # Function Invokation
  14. print(fancy_cleanup("         geronimo crikey          "))
  15. print(fancy_cleanup("         nonensense     "))
  16. print(fancy_cleanup("grade"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement