Python String Concatenation: Combine Text and Variables
Explore how to combine text and variables in Python by using string concatenation within the print function. Learn to mix strings, numbers, and variables to create dynamic and customized messages, enhancing your programming skills with practical examples.
We'll cover the following...
Now that Python can remember things, let’s make our messages more dynamic!
This lesson will teach us how to combine words and numbers to create full sentences using variables.
Mix it up
Try this code:
Awesome! We just combined strings and numbers in one line.
Why commas?
In print(), commas separate each part of our message. Python puts them together and even adds spaces for us.
We can mix:
Strings (text in quotes)
Variables (like
name,age)Numbers
All in a single print() statement.
Your turn: Build a fun message
Now swap in your own favorite things!
We just made a custom sentence using commas.