We can concatenate strings with the plus operator (+).
This program joins two strings and stores the result in message:
message := "I love coding. " + "It is fun!"
fmt.Println(message)
Output:
I love coding. It is fun!
Concatenation with variables:
String concatenation is useful when part of the message comes from a variable:
favoriteAnimal := "parrot"
message := "My favorite animal is the " + favoriteAnimal
fmt.Println(message)
Output:
My favorite animal is the parrot
Be careful to include spaces in the strings where you want spaces in the final message.
Assignment
Follow the Coding Tutorial and let's practice string concatenation!
Hint
Use + to join the strings and variables.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
