1

How can I pass \n into the dictionary

a = {'A': '\n'}

Is there any escape character? It interprets it as newline.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Ignesus
  • 33
  • 3
  • 2
    Backslash is the escape character. Or use a raw string. This has nothing to do with dictionaries, it's just the way you type string literals. – Barmar Jan 22 '20 at 21:02
  • 1
    Are you just asking how to escape a backslash? In that case, this is a duplicate of https://stackoverflow.com/q/19095796/11301900. – AMC Jan 22 '20 at 21:26
  • 1
    Does this answer your question? [How to print a single backslash?](https://stackoverflow.com/questions/19095796/how-to-print-a-single-backslash) – wjandrea Jan 22 '20 at 21:34

2 Answers2

4

You can use raw string:

a = {'A': r'\n'}
Charnel
  • 4,222
  • 2
  • 16
  • 28
4

You can use:

a = {'A': '\\n'}

or raw string as @Charnel answered:

a = {'A': r'\n'}