Python Python Basics Types and Branching If, Else and Elif

Charlie Macpherson
Charlie Macpherson
Pro Student 188 Points

Inputting a variable into a code

Why do you use:

print("You should learn Python, {}!".format(first_name))

instead of:

print("You should learn Python", first_name, "!")

1 Answer

Both work in print statements, but sometimes you aren't printing strings. For example, I might want to format something into a string I'm about to store in a variable:

world = "world"
my_variable = "Hello, {}!".format(world)