Working with Text
7 min · Go
Join strings, measure them, and format text with fmt.
Enemy 1 of 5
Strings and concatenation
This code joins two pieces of text with + and prints the result as one greeting. Press Run to see it.
Why this works
A Go string is technically a read-only sequence of bytes, most often holding UTF-8 encoded text, but for everyday use, you can think of it the same way you think of strings in any other language: a piece of text in quotes.
Two strings are joined together with the same + operator used for adding numbers; Go determines from the operand types whether + means numeric addition or string concatenation. Because Go strings are immutable (they can't be changed in place), greeting + name always produces a brand-new string rather than modifying greeting itself.
Rena
Your AI tutor. She walks you through each step.
Asking for help is part of coding. Rena reads your code and gives you a hint. She is free with an account: 20 hints a day.