CPSC120A
Fundamentals of Computer Science I

Activity 1

Exploring the backslash character.

Backslash

The backslash, that's the character above the Enter key on your keyboard that looks like this: '\', is a tricky character. Not only does it not print like you would expect it to, but it can also affect how characters around it are printed. In this activty you will explore the affects of printing the backslashes to determine the rules for its behavior.

Details

  1. Fill in the following table. For each row of the table, write a python program that prints the characters on the left. Put the result in the column on the right. If running the code produces an error, just put 'error'.

    ExecuteResult
    print('\\')
    print('\\\')
    print('\\\\')
    print('\\/\\')
    print('\\//\\')
    print('\'')
    print('\'\')
    print('\'\'')
    print('\'a\'')
    print('\n')
    print('\n\n')
    print('a\nb')
  2. Give Python code for a program that would print four backslashes in a row, '\\\\'?

  3. What is the same about all of the above examples that don't produce an error?

  4. When printing text in Python, what does the backslash character do?

  5. Why do you think the creators of the Python programming language gave the backslash character this behavior?