I was reading the book ‘Learn Python 3 the Hard Way’. In ex23,why the strings in english are not encoded?
UTF-8 was optimized to encode the original ASCII with those original codes, and then use a few extra bytes to encode other languages.
1 Like
So encode() only works for the extra language, and we use ord() for the characters in original ASCII code right?
both are built-ins but one (ord()) is to convert a char to a numeric representation, and the other one (encode()) is to convert a string to byte type from string of char.
1 Like
Yes, in theory it’s that and what @nexus6 said. ord() always gives you an number, but encode and decode work to convert the set of bytes to and from characters. Now, something I don’t know is what happens if you do ord on some unicode char that’s say utf-16.
But, I’d save that for later.
1 Like