我正在尝试从照片网址中删除一些不需要的字符。
相关代码:
for img in imgSrc:
print(img)
img.strip('US40')
print(img)
没有引发错误,但是两个打印语句的输出是相同的:
https://images-na.ssl-images-amazon.com/images/I/51uUvUZNoUL._AC_US40_.jpg
https://images-na.ssl-images-amazon.com/images/I/51uUvUZNoUL._AC_US40_.jpg
https://images-na.ssl-images-amazon.com/images/I/51GQJaFyk1L._AC_US40_.jpg
https://images-na.ssl-images-amazon.com/images/I/51GQJaFyk1L._AC_US40_.jpg
strip仅适用于前导字符和尾随字符。在这种情况下,您应该使用replace
剥离: S.strip([chars])-> str
返回删除前导和尾随空格的字符串S的副本。如果给定了chars而不是None,则改为删除chars中的字符。
替换: S.replace(old,new [,count])-> str
返回S的副本,其中所有出现的子字符串old都替换为new。如果给出了可选的参数count,则仅替换第一个出现的计数。
for img in imgSrc:
print(img)
img = img.replace('US40',"")
print(img)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句