Python: Quote String

By Xah Lee. Date: . Last updated: .

What is String

A string is a sequence of characters.

Python string is immutable. Any function that work on string returns a new string.

Quoting String

Two ways to quote a string.

String Delimiter

String can be quoted by QUOTATION MARK e.g. "abc" or APOSTROPHE e.g. 'abc'

There is no different between them.

Single Quote String

String can be created by:

they are effectively the same.

Literal linebreak is not allowed. It's syntax error.

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

No Here-String

Python does not suport Here-String (aka here-doc) , as in Perl, PHP, PowerShell.

Python, String