Solution Review: Embed a Variable in a String

Let’s go over the solution for the challenge: Embed a Variable in a String.

We'll cover the following

Task

In this challenge, you were provided two variables and you had to embed them in a string.

Solution

The first thing you had to figure out was that string interpolation can be used to embed variables into strings.

Next, you needed to write the required string in a print statement. To embed name and age in the string you had to insert a $ followed by the variable name at the location where you wanted to embed the variables.

print("$name is $age years old.");

You can find the complete solution below:

You were required to write the code given on line 5.

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy