Start learning free

LESSON 56 OF 671 · STRINGS I

Escaping Characters in Go

Lesson

Some characters have special meaning inside Go string literals. To include them as regular characters, we escape them with a backslash (\).

For example, a double quote inside a double-quoted string must be written as \":

fmt.Println("I'll study \"Coding 101\" on AlgoCademy")

Common escape sequences include:

  • \" for a double quote inside a string
  • \n for a new line
  • \\ for a literal backslash
fmt.Println("I will learn this\nNo matter what")
fmt.Println("C:\\Users\\Andy\\notion")

Assignment
Follow the Coding Tutorial and practice escaping quotes, newlines, and backslashes.


STEP 1 OF 3
    Ctrl + Enter to check