Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- x = "The sky is red"
- r = re.compile ("red")
- y = r.sub(x, "blue")
- print x # Prints "The sky is red"
- print y # Prints "blue"
- >>> y = re.sub(r, 'blue', x)
- >>> y
- 'The sky is blue'
- >>> z = r.sub('blue', x)
- >>> z
- 'The sky is blue'
- r.sub(x, "blue")
- # should be
- r.sub("blue", x)
- import re
- x = "The sky is red"
- r = re.compile ("red")
- y = r.sub("blue", x)
- print x # Prints "The sky is red"
- print y # Prints "The sky is blue"
- x= "The sky is red"
- y= x.replace("red", "blue")
- print y
- x = r.sub("blue", x)
Add Comment
Please, Sign In to add comment