print(chr(97)) # a
print(chr(98)) # b
print(chr(80)) # P
print(chr(35)) # #
print(chr(36)) # $
The first 128 unicode point values are same as ASCII values.
for i in range(200,250):
print(i,":",chr(i))
print(chr(64)) # Output: '@'
print(chr(8364)) # Output: '€' (Euro sign)
Output:
@
€
for i in range(65, 70):
print(i, ":", chr(i)) # Prints characters from A to E
Output:
65 : A
66 : B
67 : C
68 : D
69 : E
print(chr(128512)) # Output: 😀 (Smiling face emoji)
Output:
😀
print(chr(128512)) # 😀 (Grinning Face)
print(chr(128516)) # 😄 (Smiling Face)
print(chr(128525)) # 😍 (Heart Eyes)
print(chr(128640)) # 🚀 (Rocket)
print(chr(128170)) # 💪 (Flexed Biceps)
Output:
😀
😄
😍
🚀
💪
alphabet = [chr(i) for i in range(97, 123)]
print(alphabet) # Output: ['a', 'b', 'c', ..., 'z']
Output:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
ord(): Converts a character into its corresponding Unicode code point (an integer).
print(ord('A')) # Output: 65
chr(): Converts a Unicode code point (an integer) into its corresponding character.
print(chr(65)) # Output: 'A'
ord() and chr() are inverse functions, commonly used for character-to-integer and integer-to-character conversions in Python.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.