Atom

Characters

A character is one Unicode scalar. A single-quoted literal containing exactly one scalar produces a 'char'. Empty and longer single-quoted literals are strings. Triple single quotes can make a string that holds just one scalar.

Atom
letter = 'é'
word = 'éclair'
print(type(letter) == char)
print(word[0] == letter)

Output

Output
true
true

Characters compare by their text. A character and a string containing that same scalar compare equal. Use 'convert(char, value)' to convert one scalar of text or a signed integer Unicode scalar, and 'convert(string, value)' when you need a string representation.

A combining mark takes its own position. For example, text made from 'e' and a combining acute accent has two scalars. Use 'text.normalize' when canonically equivalent spellings should compare equal.

See Strings, type, and convert.

A single-quoted literal that decodes to exactly one Unicode scalar becomes a char. A zero-length or longer literal becomes a string. Triple single quotes produce a string containing the exact decoded contents, including line breaks and indentation. Escape sequences include \n, \r, \t, \0, \, ', {, }, and \u{hex}. Surrogates and scalars above U+10FFFF are invalid.