6

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.

Kiddo
  • 1,910
  • 8
  • 30
  • 54

1 Answers1

18

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
lvc
  • 34,233
  • 10
  • 73
  • 98