[Python] How to make a single backslash string

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to make a list which is literally this: '\'. But doing string = '\' raises an EOL SyntaxError. How would I do it?

    Many answers say to do string = '\\' but then when I print the string it shows as '\\' not '\'

    EDIT 1 This used to be about a list containing a string (['\'] rather than '\'). But I realised the list was not the issue. That's why some of the answers talk about a list.

    EDIT 2 This is a vscode notebook issue! More edit It doesn't happen in a standard Jupyter notebook. Even when I try to write string = '\\' to a file rather than just print it, it comes out as '\\'

    Continue reading...

Compartilhe esta Página