bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Go/Go Tutorial
Go•Go Tutorial

Go Assignment Operators

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Go Assignment Operators?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ main
3Order

Put the learning moves in the order that makes the concept easiest to apply.

In the example below, we use the assignment operator ( = ) to assign the value 10 to a variable called x :
Assignment operators are used to assign values to variables.
Assignment Operators

Assignment Operators

Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator ( = ) to assign the value 10 to a variable called x :

Example

package main
import ("fmt")
func main() {
  var x = 10
  fmt.Println(x)
}

The addition assignment operator ( += ) adds a value to a variable:

Example

package main
import ("fmt")
func main() {
  var x = 10
  x +=5
  fmt.Println(x)
}

A list of all assignment operators

OperatorExampleSame As
=x = 5x = 5
+=x += 3x = x + 3
-=x -= 3x = x - 3
*=x *= 3x = x * 3
/=x /= 3x = x / 3
%=x %= 3x = x % 3
&=x &= 3x = x & 3
=x= 3x = x3
^=x ^= 3x = x ^ 3
>>=x >>= 3x = x >> 3
<<=x <<= 3x = x << 3

Previous

Go Arithmetic Operators

Next

Go Comparison Operators