Mix Words and Numbers
Discover how to combine strings and numbers in Python using variables and the print() function. This lesson helps you build dynamic, personalized messages by mixing text, numbers, and variables in one line, enhancing your programming skills with hands-on practice.
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.