Python 1d - Using Variables
Printing Variables Within Sentences
Join sentences and variables together using a plus symbol (+). Joining sentences together like this is called concatenation.
Remember to use speech marks for your printed statements but print the variable name to display the variable value.
You need to use the + symbol before and after each variable.
Practice Task 1
1. On line 1 write a variable with the name sandwich and the value of a sandwich filling.
2. On line 2 print a sentence that uses the variable name sandwich.
3. On line 3 change the variable sandwich to equal a different filling.
4. On line 4 print the same sentence as line 2.
Printing Number Variables Within Sentences
To join strings and number values then you must use a comma as a plus will not work:
You need to use a comma before and after each variable.
Practice Task 2
1. Create a variable called bottles and give it the value 99.
2. print a sentence that uses the variable name.
3. Change the variable value to 98.
4. print the same sentence again.