Lesson goal: Literal text versus "to be text"

Previous: Testing divisibility | Home | Next: Using absolute values

When using the print statement, you might have noticed that sometimes we enclosed what we wanted to display in double quotes " and ", and sometimes we did not. What's the difference? The text you put inside of double quotes is always taken literally, on face value by the computer. It simply looks inside of the double quotes and displays exactly what's there. Thus, coding print("hello there") always results in the text hello there appearing on the screen. Literal text must always be enclosed by double quotes. If you program print(hello there) you'll get an error.

When doing calculations, we dropped the double quotes. For example, if you code print(2+2), without the double quotes, the computer does not display 2+2; you'll get 4 instead. This is because without the double quotes, the 2+2 is "to be text." This means the text that ultimately gets displayed is yet "to be" determined (it must be calculated by the computer first). Only after the computer does the internal computation, determining that 2+2 is "to be" 4 does the 4 get displayed. Look at these two lines, which you may run as code:

Move the mouse over a dotted box for more information.

In computer programming a group of characters inside of double quotes is called a "string," since the double quotes contains a literal "chain" or "string" of characters. In the top line, the 2+2 is inside of quotes, you'll see 2+2 get displayed. In the second line, the 2+2 is not inside of quotes at all, so it's not a literal string anymore, and the computer will evaluate it before displaying anything.

Now you try. Use the print statement to experiment with literal vs to-be text.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.