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
π₯ Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and projectβoriented with real examples and source code.