Python: Quote String

By Xah Lee. Date: . Last updated: .

What is String

A string is a sequence of characters.

String is Immutable

Any function that work on string returns a new string.

String Syntax

there are several syntax for string.

# single quoted string
aa = "single QUOTATION MARK"
bb = 'single APOSTROPHE'
# triple quoted string
cc = """triple QUOTATION MARK"""
dd = '''triple APOSTROPHE'''

Single Quoted String

single quoted string is designed for short string, like few words or one sentence.

in single quoted string:

# single quoted string
# APOSTROPHE delimited
yy = 'good morn'

print(yy)
# good morn
# single quoted string
# QUOTATION MARK delimited
xx = "good eve"

print(xx)
# good eve
# in single quoted string, literal linebreak character is not allowed

xx = "abc
xyz"

    # xx = "abc
         # ^
# SyntaxError: unterminated string literal (detected at line 3)

What's the difference between QUOTATION MARK, and APOSTROPHE as string delimiters

To include the delimiter in the string, you need to use String Escape Sequence, or Triple Quote String .

Triple Quote String

No Here-String

Python does not support Here-String (aka here-doc)