Variables

Variables are simply names that we can give to values such as strings, numbers, and booleans. Here’s how to make a variable named s. We say s is a string that has the value "Hello, World!". Can you describe the following variables?

Press run.

alt text

Variables are not printed out to the console. Instead, the variable simply saves the string, number, or boolean into the computer’s memory. We can use these variables in other statements.

For example, the following code would print "Hello Nuevo Foundation" to the console:

  • str1 = "Hello"

  • str2 = "Nuevo Foundation"

  • print(str1 + " " + str2)

You can also do the following to print strings together while adding spaces in between the words.

  • str1 = "Hello"

  • str2 = "Nuevo Foundation"

  • print(str1, str2)