How to Join Strings in Go with the + Operator
The simplest way to build text from pieces in Go is the + operator: first + " " + last. Go only joins strings with strings, so a number has to become text first.
Syntax
<text> := <string> + <string>
<text> += <string>
| Part | What it does |
|---|---|
<string> + <string> | A new string with the second joined to the first. Both sides must be strings. |
<text> += <string> | Joins the string onto the end of <text> and stores the result in <text>. |
The Go language specification on string concatenation: "Strings can be concatenated using the + operator or the += assignment operator".
The Example
The example joins a first and a last name with a space, joins a sentence with a year turned into text by fmt.Sprint, and builds a greeting with +=.
Prerequisites
- Go.
go runcompiles and runs a single file. This guide uses Go 1.27.4.
Step 1: Write the Code
Create a file named main.go:

package main
import "fmt"
func main() {
first := "Ada"
last := "Lovelace"
year := 1815
full := first + " " + last
fmt.Println(full)
fmt.Println(full + " was born in " + fmt.Sprint(year))
greeting := "Hello"
greeting += ", " + first
fmt.Println(greeting)
}
Step 2: Run It
go run main.go
Ada Lovelace
Ada Lovelace was born in 1815
Hello, Ada

The command is the same in zsh, bash and PowerShell.
What Happened
first + " " + lastjoined three strings into one.fmt.Sprint(year)turned the number1815into the text"1815", so it could be joined.greeting += ", " + firstjoined", Ada"ontoHelloand stored the result back ingreeting.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Joining a string and a number, as in "born " + year | It doesn't compile: invalid operation: "born " + year (mismatched types untyped string and int) | Convert first: fmt.Sprint(year) or strconv.Itoa(year) |
Converting a number with string(year) | It gives the character with that code, ܗ, not 1815, and go vet warns about it | Use strconv.Itoa(year) |
Building a long string with += in a big loop | Each += copies the whole string so far | Use a strings.Builder |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
mismatched types untyped string and int | One side of + is a number | Convert the number to a string |
| An odd character where a number should be | string(n) was used on an integer | Use strconv.Itoa(n) |
FAQ
Is there a function for joining many strings with a separator?
Yes: strings.Join([]string{"a", "b", "c"}, ", ") gives a, b, c.
When should I use fmt.Sprintf instead?
When the text mixes several values and formats: fmt.Sprintf("%s was born in %d", name, year) reads more easily than a chain of +.
Conclusion
a + b joins two strings into a new one and s += t adds to a string. Both sides must be strings, so turn numbers into text first with fmt.Sprint or strconv.Itoa.
Additional Resources
- String concatenation, in the Go language specification.
- strconv.Itoa and strings.Builder, in the Go documentation.
