A string is a sequence of code points
The topic Functions finished the skeleton of a program: values and names, branches and loops, and functions that give repeated code a name. Almost every program also reads and writes text: file names, log lines, tables of metrics, and in natural language processing the data itself. Text looks simple and is not. A letter can take one byte in a file or four, and two strings that look the same can compare unequal.
A Python string, str, is a sequence of code points. A code point is the number that Unicode assigns to a character. It is written as U+ and at least four hexadecimal digits: U+0041 is A, U+20AC is €. The function ord gives the code point of a one-character string, and chr goes back:
s = "naïve €"
print(len(s))
print(ord("n"), ord("ï"), ord("€"))
print(chr(239), chr(8364), s[2])
print(type(s[2]), len(s[2]))7
110 239 8364
ï € ï
<class 'str'> 1The string holds seven code points: five letters, a space and the euro sign. len counts code points, and indices count them too: s[2] is the third one, ï. The number 8364 is 20AC in hexadecimal, so chr(8364) is U+20AC. Python has no separate character type: an element of a string is again a string, of length 1.
Every character has its code point: Latin and Cyrillic letters, Chinese characters, mathematical symbols. Even the cat emoji 🐈 is a single code point, U+1F408.