USING THE SPLIT() FUNCTION TO DISPLAY CHARACTERS IN A STRING
Listing 2.8 shows the content of StringChars1.py, which illustrates how to print the characters in a text string.
Listing 2.8: StringChars1.py
text = 'abcdef'
for ch in text:
print('char:',ch,'ord value:',ord(ch))
print()
Listing 2.8 is straightforward: A for loop iterates through the characters in the string text and then prints the character and its ord value. The output from Listing 2.8 is here:
('char:', 'a', 'ord value:', 97)
('char:', 'b', 'ord value:', 98)
('char:', 'c', 'ord value:', 99)
('char:', 'd', 'ord value:', 100)
('char:', 'e', 'ord value:', 101)
('char:', 'f', 'ord value:', 102)