Start learning free

LESSON 8 OF 671 · WELCOME TO GO

String Concatenation in Go

Lesson

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.


STEP 1 OF 1
    Ctrl + Enter to check