ISF DP Computer Science

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 shell

To exit the shell, type control + D or type exit.


[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])