Unicode #
This lab explores Unicode and invisible characters.
[0] Setup #
We will do these experiments in the python shell. ๐ป Enter the python shell
python3
you will know you’re in the shell if it looks like this:
>>>
๐พ ๐ฌ Exiting the shellTo exit the shell, type
control+Dor typeexit.
[1] Print Unicode as integers #
๐ป The ord() function prints unicode as integers
For example:.
char_a = 'A'
char_tree = 'ๆจน'
char_poo = '๐ฉ'
>>>ord(char_tree)
>>>ord(char_tree)
>>>ord(char_poo)
๐ป Experiment by printing out some different characters
You can see integer representation is longer for some than it is for others
[2] Invisible characters #
Some emojis have variations, such as different skin and hair colors
๐ป Save an emoji that has variations into a variable
char_man = '๐๐ป'
char_painter = '๐ฉ๐ฝโ๐จ'
When you try to print them out as a whole, you may get an error.
๐ป Print each piece of the emoji separately
>>>ord(char_painter[0])
>>>ord(char_painter[1])
>>>ord(char_painter[2])
>>>ord(char_painter[3])