Hi Geeks, In this tutorial we are going to have a look on
ord() methods. These two functions are opposite to one another. One method returns the character whereas another method returns the Unicode code point. These are very simple and useful methods to learn, right now.
These two methods are very useful when we want to convert a Unicode code point to a character or find the character's Unicode code point.
Let's have a look at these functions one by one.
This method converts a Unicode code point into a character. For example, If you give 8364 as input it returns € as output.
char( i ) # i must be an integer
This method takes only parameter as an input and the parameter must be an integer.
The valid range of the integer is from 0 through 1,114,111.
one = chr(100) two = chr(110) three = chr(120) print(one) print(two) print(three)
d n x
This method converts a Character into a Unicode code point. For example, If you give 'P' as input it returns 80 as output.
ord( c ) # c must be an string
This method takes only parameter as an input and the parameter must be an Character(a String).
one = ord('A') two = ord('$') three = ord('~') print(one) print(two) print(three)
65 36 126
Pheww! This is it. I hope that you enjoyed the post and learned about the chr()and ord() python library functions. If you feel that this post is useful, please share it with your friends and colleagues.
Thanks for reading it till the end.
SHARE YOUR THOUGHTS WITH US!