Text in quotes

What's common between messengers, Google Maps, Netflix, alarm clocks, and most of other software? All of them show information on screens. This generic task is one of the core goals of modern software. We shall try to achieve a simple version of that goal: to output text on the screen (when working in REPL.it, the "screen" is the console). But before we deal with outputting, we need to write the text into the program somehow. Just write Pasta Carbonara in the editor (white area), then click β–Ί:

Oops! Something's wrong. Recall, this is what the interpreter did after we pressed β–Ί:

  1. Read your program (two words).
  2. Tried to understand it, constrained by the syntax rules.
  3. If the code was valid, did whatever the code said to do.

Our code contained two words: Pasta Carbonara. We wanted it to "understand" that information as text, but the error message produced by the interpreter indicates that we've failed and violated the syntax rules.

Python interpreter is akin to a very peculiar waiter. Just imagine how such a waiter reacts to something he or she doesn't understand. A small story for you to comprehend what’s going on. One day Jane walked into a restaurant called Literal Joe's. Their slogan is "We Believe in Unequivocal Communication". The waiter was at the table immediately, silent and awkward. Jane looked at the waiter and said:

β€” Pasta Carbonara

The waiter replied:

β€” SyntaxError: invalid syntax.

Well, damn. Jane took out her smartphone and googled "waiter at Literal Joe's" and found a tip. This restaurant is rather difficult! You can't just say things, you have to put them in quotes. She did her best at making air quotes and repeated "Pasta Carbonara".

Go ahead and wrap the text in the editor with quotation marks. Or you can just delete the previous text and copy-paste "Pasta Carbonara". Press β–Ί. No error. And no pasta. The interpreter understood "Pasta Carbonara" as valid text, created it in the memory, but then deleted it right away. We didn't tell this peculiar interpreter to show the text on the screen.

Neither did Jane receive any pasta. The waiter seemed happy, silently went away, and returned empty-handed. Jane googled again, and it turns out that saying the name of a dish wasn't enough still! The waiter did understand her and did pass the order to the kitchen. They prepared the dish, but then trashed it. Jane didn't tell this peculiar waiter to bring the dish to her. In our analogy Jane is the programmer, the waiter is the interpreter and the goal of bringing the dish is printing text. In order to achieve the goal, you need to understand how the interpreter treats text and how special code can operate on it.

We want to warn you about trying to dig up error messages you encounter. Such attempts aren't dangerous, but can lead you to misunderstanding of internal concepts of programming. In a short period of time you will be able to tell what exactly each error is pointing to. But for now stick to those details on which we put focus.


Summary:

  1. A programming language interpreter is very actual, it does not assume anything.
  2. Code must explicitly express your desires.
  3. A lot of things happen without you knowing or seeing. You didn't know, but pasta was cooked for real!