知识卡片
原始字符串只改变转义处理层次
Python原始字符串让大多数反斜杠按字面进入字符串,便于再交由正则引擎解释。它不是关闭正则的特殊字符,也不使模式自动正确;普通字符串与正则各自的转义层应分开看。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
Tip The r before the apostrophe (r') indicates that the quoted string literal is a raw string. A Python raw string just makes it easier to use the backslashes used to escape special symbols within a regular expression. If you tell Python that a string is raw, it will skip processing the backslashes and pass them on to the regular expression parser (re package). Otherwise,
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》第01章《会读写的机器与自然语言处理》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-1.html)
- 结论依据:摘录中关于原始字符串只改变转义处理层次的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:Tip The r before the apostrophe (r') indicates that the quoted string literal is a raw string. A Python raw string just makes it easier to use the backslashes used to escape special symbols within a regular expression. If you tell Python that a string is raw, it will skip processing the backslashes and pass them on to the regular expression parser (re package). Otherwise,