If we need to interpolate a string, without printing it, then we can use fmt.Sprintf().

Just like fmt.Printf(), fmt.Sprintf() can also use verbs:

correctAns := "A" answer := fmt.Sprintf("And the correct answer is… %v!", correctAns) fmt.Print(answer) // Prints: And the correct answer is… A!

fmt.Sprintf() works very similarly to fmt.Printf(), the major difference is that fmt.Sprintf() returns its value instead of printing it out!



Assign to wish the value of calling fmt.Sprintf() with the values template and pet.

wish should then contain the interpolated string "I wish I had a puppy.".

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?