filmov
tv
What are Functions of Python | Ord() and Chr() Functions in Python
Показать описание
chr(): This is a built-in function in Python that returns a string representing a character whose Unicode code point is the integer passed into the function.
try This Code out:
# Using chr() to convert ASCII value to character
print(chr(65)) # Output: 'A'
# Using chr() with loop to print alphabets
for i in range(97, 123):
print(chr(i), end=" ") # 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'
other information:
The chr() function takes an integer as an argument, which should be in the range 0 through 1,114,111 (inclusive). It's important to note that the chr() function can handle any Unicode character, not just ASCII characters (which range from 0 to 127).
***************************************************************************
ord(): This is a built-in function in Python that returns an integer representing the Unicode character.
Try this code out
# Using ord() to convert character to ASCII value
print(ord('A')) # Output: 65
# Using ord() with loop to print ASCII values of alphabets
for char in 'abcdefghijklmnopqrstuvwxyz':
print(ord(char), end=" ")
# Output: 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
The ord() function takes a string of length one as an argument and returns a Unicode code point representation of the passed argument.
Essentially, chr() and ord() are complementary functions. ord() transforms a single character into its corresponding integer Unicode code point, and chr() takes a Unicode code point and returns its corresponding character.
try This Code out:
# Using chr() to convert ASCII value to character
print(chr(65)) # Output: 'A'
# Using chr() with loop to print alphabets
for i in range(97, 123):
print(chr(i), end=" ") # 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'
other information:
The chr() function takes an integer as an argument, which should be in the range 0 through 1,114,111 (inclusive). It's important to note that the chr() function can handle any Unicode character, not just ASCII characters (which range from 0 to 127).
***************************************************************************
ord(): This is a built-in function in Python that returns an integer representing the Unicode character.
Try this code out
# Using ord() to convert character to ASCII value
print(ord('A')) # Output: 65
# Using ord() with loop to print ASCII values of alphabets
for char in 'abcdefghijklmnopqrstuvwxyz':
print(ord(char), end=" ")
# Output: 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
The ord() function takes a string of length one as an argument and returns a Unicode code point representation of the passed argument.
Essentially, chr() and ord() are complementary functions. ord() transforms a single character into its corresponding integer Unicode code point, and chr() takes a Unicode code point and returns its corresponding character.