Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import re
  2. x = "The sky is red"
  3. r = re.compile ("red")
  4. y = r.sub(x, "blue")
  5. print x # Prints "The sky is red"
  6. print y # Prints "blue"
  7.  
  8. >>> y = re.sub(r, 'blue', x)
  9. >>> y
  10. 'The sky is blue'
  11.  
  12. >>> z = r.sub('blue', x)
  13. >>> z
  14. 'The sky is blue'
  15.  
  16. r.sub(x, "blue")
  17. # should be
  18. r.sub("blue", x)
  19.  
  20. import re
  21. x = "The sky is red"
  22. r = re.compile ("red")
  23. y = r.sub("blue", x)
  24. print x # Prints "The sky is red"
  25. print y # Prints "The sky is blue"
  26.  
  27. x= "The sky is red"
  28. y= x.replace("red", "blue")
  29. print y
  30.  
  31. x = r.sub("blue", x)
Add Comment
Please, Sign In to add comment