I would like to remove "http://" in a string that contains a web URL i.e: "http://www.google.com". My code is:
import os
s = 'http://www.google.com'
s.replace("http://","")
print s
I try to replace http:// with a space but somehow it still prints out http://www.google.com
Am i using replace incorrectly here? Thanks for your answer.
Strings are immutable. That means none of their methods change the existing string - rather, they give you back a new one. So, you need to assign the result back to a variable (the same, or a different, one):
s = 'http://www.google.com'
s = s.replace("http://","")
print s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With