Go Operators

Operators in Go are tools for performing operations on variables and values. For example, the + operator can be used to add two values together.

Tutorials dojo strip



Example:

package main
import ("fmt")

func main() {
  var total = 11 + 8
  fmt.Println(total)
}

Output:

19




The + operator can also add a variable with a value or another variable:

Example:

package main
import ("fmt")

func main() {
  var (
    horsepower1 = 100 + 50      // 150
    horsepower2 = horsepower1 + 250 // 400
    totalHorsepower = horsepower2 + horsepower2 // 800
  )
  fmt.Println(totalHorsepower)
}

Output:

800




Types of Go Operators

Go divides its operators into the following categories:

  1. Arithmetic operators
  2. Assignment operators
  3. Comparison operators
  4. Logical operators
  5. Bitwise operators
Tutorials dojo strip
Scroll to Top