Python Beginner - How to insert variable in a string text?

Hi There,

I’m new to Codecademy, and I’m currently learning “variable”.
During the session, we tried to set a variable and print out the variable. However, I’d like to know, when I print out the variable, can I insert this variable in a text string?

For example, the current exercise is as below:
Python Syntax - Variables


I want to know, if I’d like to print our something like “The lunch is Pasta” instead of print(“Lunch:”) print(meal). How could I insert a variable in a string?

Among the first string operations we learn addresses your question… Concatenation.

string_literal + variable

Only the string literal is in quotes. Be sure to account for the space between.

It works! Thanks for your help!

1 Like