Python 中的replace 和strip

Python 中的replace 和strip,第1张

Python 中的replace 和strip

[摘要]
怎么去掉引号 替换字符串中的某些字符

replace(原字符/对象 ,新字符/对象,替换几次)

strip 去杂

例 改成 标准列表

('型号', '单价'),('型号', '单价')	→  ['型号', ' 单价'],['型号', ' 单价']
  • 方式1 不但括号去不掉, 还加了一堆引号和逗号
	print("".join(str(cell)).split())
	→  ["('型号',", "'单价')"]
  • 方式 2 括号和逗号去了 ,引号 留了半边
print"".join(str(cell)).strip("()").strip(''').strip(''').split(","))
→ ["型号'", " '单价"]
  • 方式 3 ""替换成 空格 okok
 print("去杂","".join(str(cell)).strip("()").replace(''', '').split(","))
  print(str(cell).strip("()").replace("'","").split(","))
 →['型号', ' 单价']

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5651827.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存