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 multiple syntax for string.

example

Single Quoted String (For Single Line, Short String)

example

String with different delimiters basically have the same meaning. Only difference is that QUOTATION MARK quoted cannot contain unescaped QUOTATION MARK, and APOSTROPHE quoted cannot contain unescaped APOSTROPHE. (escape means backslash character sequence. 〔see Python: String Escape Sequence〕)

in single quoted string:

xx = "this is string"

yy = 'another string'

print(xx, yy)
# Literal linebreak is not allowed

xx = "abc
xyz"

#     xx = "abc
#             ^
# SyntaxError: EOL while scanning string literal
# error: cannot format -: Cannot parse: 1:3: a = "abc

Triple Quote String

No Here-String

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

Python, String