Start learning free

LESSON 13 OF 671 · VARIABLES

Constants in Go

Lesson

A constant is a named value that cannot be reassigned after it is declared.

In Go, use the const keyword:

const pi = 3.14

fmt.Println(pi)

Constants are useful for values that should not change while the program runs.

If you try to assign a new value to a constant, Go will produce an error.


Assignment
Fix the code so it prints 3.14 without an error.


Hint
Remove the line that tries to assign a new value to pi.


STEP 1 OF 1
    Ctrl + Enter to check