Python Escape Sequences, Text, and Unicode Characters

preview_player
Показать описание
Since Python 3.0, strings are stored as Unicode, where each character in the string is represented by a unique number called a code point. For example, the character ‘J' has the code point decimal value of 74. There is more than 1 million code points in the Unicode standard character set. For efficient storage of these strings, encoding converts the sequence of code points into a set of bytes.

Python has the following escape sequences
\n - new line
\t – tab or indent
\’ – single quote
\” - double quote
\\ - backslash

You can ignore escape sequences by using a raw string. A raw string is created by adding an 'r' before a string literal, as in r'this is a test\'', which would output as this is a test\’.

Converting between a text character and it’s encoded value may be useful. The built-in ord() function returns an encoded integer value for a string of length one. The built-in chr() function returns a single character string for an encoded integer.

Ex: chr(75) returns K
Ex: ord(‘B’) returns 66

Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!
Рекомендации по теме
Комментарии
Автор

Nice quick tutorial. Great demo. Thanks!

vkhan