Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

The print() function - the escape and newline characters

This convention has two important consequences:

  1. If you want to put just one backslash inside a string, don't forget its escaping nature - you have to double it, e.g., such an invocation will cause an error:
    print("\")
    while this one won't"
    pritn("\\")
  2. Not all escape pairs (the backslash coupled with another character) mean something. 
    Experiment with your code in the editor, run it and see what happens. 

The print() function - using multiple arguments

So far we have teste the print()  function behavior with no arguments, and with one argument. It's also worth trying to feed the print() function with more than one argument. 

Look at the editor window. This is what we're going to test now. 

There is one print() function invocation, but it contains three arguments. All of them are strings. 

The arguments are separated by commas. We've surrounded them with spaces to make them more visible, but it's not really necessary, and we won't be doing it anymore.

In this case, the commas separating the arguments play a completely different role than the comma inside the string. The former is a part of Python's syntax, the latter is intended to be shown in the console. 

If you look at the code again, you'll see that there are no spaces inside the strings. 

Run the code and see what happens. 

The console should now be showing the following text. 

The itsy bitsy spider climbed up the waterspout.

The spaces, removed from the strings; have appeared again. Can you explain why? 

Two conclusions emerge from this example: 

  • a print() function invoked with more than one argument outputs them all on one line;
  • the print() function puts a space between the outputted arguments on its own initiative.