In the Hello World section, you practiced displaying text
on the screen. Technically, you sent the words to the console, which is a
simple window where the user can type commands or view output. We used the
We call the function using the syntax
print(). When the code runs, we
want it to tell the computer, Please display what is inside the () on the
screen. For us, the word
When we run the program, the compiler works behind the scenes to convert
into the 0s and 1s that tell the computer: Show this information in the
Run the example below, and note the difference between the outputs:
Observations line by line:
- In the line 2, we print some text, which is surrounded by quotes.
- In the line 3, we print a number. Note the absence of quote marks.
- In line 4, we use four words separated by commas, all within the same
set of parentheses
(). When the words print, they show up on the same line separated by spaces.
- The code in line 5 puts extra spaces after the commas. How does this affect the output?
- Line 6 prints two words, but in this case the code uses
+instead of a comma. This prints the words without spaces in between.
- Line 7 prints text and a number with a space in between.
3.4.2. Two Special Characters¶
For all of the examples above, each time we use
For the computer, newline as an invisible character that tells the machine to
move to the next line. We can use this invisible character by adding the
Experiment with the newline character by adding these lines to the editor above:
In addition to the newline character, there is also a special tab character,
\t. Go back to the examples above and play around with using