Here is a snippet from the middle or the lesson, where we start to address string variables:
In addition to numbers, you can also create other types of variables. One of the most useful is a ‘string’ type - that is, a string of alpha-numeric characters jammed together. For instance:
stringBox = ‘string of characters ‘
brain.print(stringBox)
Stop the video and run the code here.
That did what it’s supposed to, but “24string of characters” is a bit difficult to read. We can make that easier to read by adding a line break after each thing we print. Your whole code should now look like this:
numericBox = 2
brain.print(numericBox)
brain.new_line()
anotherBox = numericBox + 2
brain.print(anotherBox)
brain.new_line()
stringBox = ‘string of characters ‘
brain.print(stringBox)
brain.new_line()
Run that and you’ll see how much easier it is to read.
Great! You can also add strings together, but they don’t add like numbers. Let’s include this:
stringBox = stringBox + ‘that can be added’
brain.print(stringBox)
brain.new_line()
What?! This is a special type of adding that we call “concatenation.” Python added the second string to the end of the first string (which was already in the box) and came up with a long string of characters. Notice also that stringBox is on both sides of the statement {stringBox = stringBox + ‘that can be added.} This is not a mistake - it’s a bit of syntactic sugar. Python (and most other languages) use the order of operations to allow you to use the current value of a variable on the right side of the equals sign in the calculation that results in the value on the left. Once the calculation is done, the new value will be the result of the calculation and the old value will be forgotten.
In the first version of the lesson, ‘string of characters ‘ was wrapped in double quotes (i use C# more than SQL) and a student ran into trouble with that. i looked at her code and it was all right, so we changed it to single quotes and it worked. Based on that, i updated the lesson to single quotes everywhere i had double quotes for string values. I did not try it on my machine, i saw that only single quotes worked on her machine, so i updated the lesson to all single quotes instead of double.
When the next student tried the same lesson, it didn’t work again, and i found that only double quotes worked for him. It’s likely it was a different computer from the first, but all of our computers are the same model of Lenovo running updated Windows 11, so they should work roughly the same.
i thought, “huh - i thought i updated the lesson, but maybe i didn’t.” We tried double quotes, and it worked. Then i went back to the lesson history and i can see that i did update the lesson. So, i tried it on my personal computer, which is an HP Envy running the latest Windows - and unexpectedly, both single and double quotes worked for me.
Either of the students could have typed it out, but it’s more likely that they copied it from the Google page i shared with them. Either way, i reviewed both and they were correct. I typed it instead of copying it on my laptop and probably had them just type the quote changes when we changed them.
I hope that’s enough information, but i’ll be happy to provide any more that i can.