Search code examples
pythoncwhitespace

How do I print the characters "\n" instead of whitespace using python and C?


I want to print the specific characters \n in python and C language. Of course its the newline character so every time I say print("\n") or printf("\n") it simply prints whitespace. What I want are the specific characters \ and n as the output. Could someone please help with this?


Solution

  • In C you need to add another "\" to your code like this.

    #include <stdio.h>
    main() {
      printf("\\n");
    }
    

    For Python you can use repr

    >>> string = "\n"
    >>> print(repr(string))
    '\n'