Section 2.13 More About Strings
Strings in Python can be enclosed in either single quotes (
'
), double quotes ("
- the double quote character), or three of the same separate quote characters ('''
or """
). When you run the following program, you will see that Python recognizes them all as strings with type str
.Double quoted strings can contain single quotes inside them, as in
"Bruce's beard"
, and single quoted strings can have double quotes inside them, as in 'The knights who say "Ni!"'
.Strings enclosed with three occurrences of either quote symbol are called triple quoted strings. They can contain either single or double quotes:
Triple quoted strings can even span multiple lines:
Python doesn’t care whether you use single or double quotes or the three-of-a-kind quotes to surround your strings. Once it has parsed the text of your program or command, the way it stores the value is identical in all cases, and the surrounding quotes are not part of the value.