python如何使用replace从字符串中删除http

python如何使用replace从字符串中删除http,python,regex,string,Python,Regex,String,我想删除包含web URL的字符串中的“http://”,即:“”。我的代码是: import os s = 'http://www.google.com' s.replace("http://","") print s 我试图用一个空格替换http://但不知怎么的,它仍然打印出来 我在这里使用的替换错误吗?谢谢您的回答。字符串是不可变的。这意味着他们的方法都不会更改现有字符串,而是会返回一个新字符串。因此,您需要将结果分配回一个变量(相同或不同的变量): 天哪,我真傻。。。非常感谢,即使您

我想删除包含web URL的字符串中的“http://”,即:“”。我的代码是:

import os
s = 'http://www.google.com'
s.replace("http://","")
print s
我试图用一个空格替换http://但不知怎么的,它仍然打印出来


我在这里使用的替换错误吗?谢谢您的回答。

字符串是不可变的。这意味着他们的方法都不会更改现有字符串,而是会返回一个新字符串。因此,您需要将结果分配回一个变量(相同或不同的变量):


天哪,我真傻。。。非常感谢,即使您可以尝试:s.split('/')[1:]或s[7:]
s = 'http://www.google.com'
s = s.replace("http://","")
print s