Why are the string characters being printed as integer numbers?

Asked

Viewed 54 times

-1

I have to analyze a code snippet and explain how it works, but I can’t figure out the output:

Code:

word_norm = 'mundo'.encode("utf8").lower()
for idx, value in enumerate(word_norm):
    print(idx, value);

Exit

0 109
1 117
2 110
3 100
4 111

I don’t understand the variable value value of the for cycle. Any idea what the whole value means? I was hoping to see each character of the word world.

  • Do not use images to show code or outputs. It is difficult to execute for those who are responding, difficult to index to the site search and impossible to understand for screen readers users.

1 answer

3


Documentation of the function encode() says that a returns array of bytes, so this is what you have, a collection of bytes, not of characters. Either you should not use this function or you should use one that turns into string again decode(), which may not be what I wanted to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.