1. Home
  2. Computing & Technology
  3. Python

Beginning Python: Data Types

From Al Lukaszewski, for About.com

5 of 10

Strings - Part 3

"But what do I do if I need to use a single quote when I already started with a single quote? Won't Python get confused?" It certainly will. If you use single quotes around the value, double quotes in the value are fine. Similarly, if you use double quotes around the value, single quotes are allowed in the value itself. However, if the value contains the same mark as the one used around it, you must use escape that part of the value.

Escaping is a fancy way of saying that you break out of the norm. It happens within quotation-like arguments when one places a backslash in front of a character like: "\n". When certain characters are 'escaped' they take on a different meaning. So, while a single quote may indicate a string's value, an escaped single quote within that value means something else: an actual single quote! The same is true for double quotes.

For more escaping, see the page "Escape Sequences".

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.