1.2.3 Special Characters

Video

1.2.3 Special Characters

Python, like most other programming languages, has a set of special characters that you learn over time as a programmer. This video will show you several of them and how to use them, but this table contains a full list. Don't worry if some of their definitions are unfamiliar and feel free to experiment and see what they do!

Try It Yourself

The code editor below is pre-loaded with the special_characters.py file. This example shows three important special characters:

  1. \' - Escape single quote (allows using single quotes inside single-quoted strings)
  2. \n - New line (creates a line break)
  3. \t - Tab (creates spacing for columns)

Steps to follow:

  1. Run the code - Click "Run" to see how each special character works
  2. Experiment - Try combining multiple special characters
  3. Create your own - Write a message using tabs and newlines to format it nicely
message = 'It\'s my birthday'  # Escape the apostrophe
print('Happy\nbirthday')      # New line
print('Happy\tbirthday')      # Tab spacing

Note: The video shows creating a file in Spyder, but you're using the browser-based editor instead. The concepts are the same - you can edit code, run it, and see the output just like in the video!

Loading Python environment...