Skip to main content

Go Operators

An operator is a symbol that tells Go to do some work with values or variables, such as adding them together.

A familiar one is +, which gives you the sum of two numbers:

Example

Prompt
Add two numbers together using the + operator and print the result.
Output: Go program and captured output

Example

The + operator isn't limited to plain numbers. Each side can be a number or a variable, so you can mix the two or sum two variables:

Prompt
Use the + operator to add values and variables together in multiple steps. Print the final sum.
Output: Go program and captured output