Start learning free

LESSON 12 OF 404 · VARIABLES

Variable Reassignment in Go

Lesson

You can change the value stored in a variable with the assignment operator =.

myVar := 5
myVar = 10

fmt.Println(myVar) // Output: 10

The first line creates myVar. The second line reassigns it to a new value.


Assigning the value of one variable to another:

myVar := 5
myNum := 10

myVar = myNum

fmt.Println(myVar) // Output: 10

After the assignment, myVar has the same value as myNum.


Assignment
Follow the Coding Tutorial and reassign the variables in the marked area.


Hint
Use =, not :=, because the variables already exist.


STEP 1 OF 1
    Ctrl + Enter to check