首页 > 解决方案 > Is there a way to write single backslash within lists?

问题描述

enter image description here is there a way to print single backslash within list?

标签: pythonpython-3.8

解决方案


关于你问题的第一个版本,我写了这个:

  1. 首先,这个表达式x='\'在 Python 中的 Python 中是不正确的。您应该这样说:x='\\',因为反斜杠是python中的特殊字符。

  2. 其次,试试这个:

l=['\\'] print(l) 这将打印:['\\']

但是当你执行 this: 时print(l[0]),它会渲染 this '\'。所以基本上,这['\\']是在列表中打印反斜杠的方法。


推荐阅读