Python how to remove http from string using

I would like to remove "http: //" in the line containing the web URL ie: " http://www.google.com ". My code is:

import os
s = 'http://www.google.com'
s.replace("http://","")
print s

I'm trying to replace http: // with a space, but somehow it gives out http://www.google.com

Am I using the wrong replacement here? Thanks for your reply.

+4
source share
1 answer

Lines are immutable. This means that none of their methods modifies the existing string - rather, they will return a new one to you. So, you need to assign the result back to a variable (same or different):

s = 'http://www.google.com'
s = s.replace("http://","")
print s
+11
source

Source: https://habr.com/ru/post/1535138/


All Articles