How to print a single backslash?

后端 未结 4 860
别跟我提以往
别跟我提以往 2020-11-22 01:43

When I write print(\'\\\') or print(\"\\\") or print(\"\'\\\'\"), Python doesn\'t print the backslash \\ symbol. Instead

4条回答
  •  无人共我
    2020-11-22 02:26

    A hacky way of printing a backslash that doesn't involve escaping is to pass its character code to chr:

    >>> print(chr(92))
    \
    

提交回复
热议问题