Menu
Coddy logo textTech

Assignment Operator

Part of the Fundamentals section of Coddy's GO journey — lesson 18 of 109.

The assignment operator (=) assigns a value to a variable. It's how we store new values in existing variables.

Create a variable and assign a value:

var score int
score = 100
fmt.Println(score)

Output:

100

You can also reassign values to change a variable:

score = 150
fmt.Println("Updated score:", score)

Output:

Updated score: 150
challenge icon

Challenge

Beginner

In this challenge, you'll practice using the assignment operator (=) in Go.

We've created some variables for you. Your task is to use the assignment operator to change the value of the favoriteColor variable to "blue" and then print it out.

Cheat sheet

The assignment operator (=) assigns a value to a variable:

var score int
score = 100
fmt.Println(score) // Output: 100

You can reassign values to change a variable:

score = 150
fmt.Println("Updated score:", score) // Output: Updated score: 150

Try it yourself

package main

import "fmt"

func main() {
	// This variable is already declared
	favoriteColor := "red"
	
	// TODO: Use the assignment operator (=) to change favoriteColor to "blue"
	
	// This will print the value of favoriteColor
	fmt.Println("My favorite color is:", favoriteColor)
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals