python - 为什么这段代码不会删除我在 Python 中的反斜杠?
问题描述
我有一个字符串格式的代码块。它的变量名 my_string 如下所示:
'<div class="section page-centered"><div><b style="font-size: 24px">About
Us</b></div><div>At <a href="https://close.com/" class="postings-
link">Close</a>, we\'re building the sales
communication platform of the future. With our roots as the very first
sales CRM to include built-in calling, we\'re leading the industry toward
eliminating manual processes and helping compa
nies to close more deals (faster). Since our founding in 2013, we\'ve
grown to become a profitable, 100% globally distributed team of ~33 high-
performing, happy people that are dedicated to b
uilding a product our customers love. </div>'
我想将除反斜杠之外的所有内容都保留在该块中。我在这里看到了很多问题和答案
new_string = my_string.replace("\\", "")
但我只是得到相同的输出。我在这里做错了什么?
解决方案
反斜杠实际上是在转义单引号。如果我打印字符串,我会得到:
print('<div class ... </div>')
<div class="section page-centered"><div><b style="font-size: 24px">About Us</b></div><div>At <a href="https://close.com/" class="postings- link">Close</a>, we're building the salescommunication platform of the future. With our roots as the very first sales CRM to include built-in calling, we're leading the industry toward eliminating manual processes and helping companies to close more deals (faster). Since our founding in 2013, we've grown to become a profitable, 100% globally distributed team of ~33 high- performing, happy people that are dedicated to building a product our customers love. </div>
推荐阅读
- snowflake-cloud-data-platform - 可以通过从另一列复制数据类型来创建表列吗?(例如 Oracle 中的 %type)
- python - Python dict.get 返回 0 评估为 false
- python - 从 scipy.interpolate 导入 RegularGridInterpolator 时出错
- sql - SQL:使用临时表和一列的 JOIN 问题
- c# - System.Net.WebException:“底层连接已关闭:接收时发生意外错误。”
- javascript - jQuery轮播幻灯片动画
- android - 使用 Android Studio 更新实时数据库中保存的数据
- laravel - 图像源不可读(我做错了什么)?
- windows - MinGW gfortran 编译器无法编译简单的测试程序
- javascript - POST/GET 请求 w/JavaScript 和 Python 文件以及 HTML 站点