Python 1d - Using Variables

Printing Variables Within Sentences

Add sentences and variable string values 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 Filling and the value of a sandwich filling.

2. On line 2 print a sentence that uses the variable name Filling.

3. On line 3 change the variable Filling to equal a different filling.

4. On line 4 print the same sentence as line 2.

Example solution:

Printing Number Variables Within Sentences

If you want to match together strings and number values then it is easiest to 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.

Example solution:

© CSNewbs 2019