Python: Get the ASCII value of a character
Python Basic: Exercise-86 with Solution
Write a Python program to get the ASCII value of a character.
ASCII (Listeni/ˈæski/ ass-kee), abbreviated from American Standard Code for Information Interchange, is a character encoding standard. ASCII codes represent text in computers, telecommunications equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they support many additional characters.
Sample Solution:-
print()
print(ord('a'))
print(ord('A'))
print(ord('1'))
print(ord('@'))
print()
Sample Output:
97 65 49 64
for i in range(ord('A'), ord('Z')+1):
print(chr(i),'==>',i)
================= RESTART: F:/Python_APSC/py-ex-basic-86.py =================
A ==> 65
B ==> 66
C ==> 67
D ==> 68
E ==> 69
F ==> 70
G ==> 71
H ==> 72
I ==> 73
J ==> 74
K ==> 75
L ==> 76
M ==> 77
N ==> 78
O ==> 79
P ==> 80
Q ==> 81
R ==> 82
S ==> 83
T ==> 84
U ==> 85
V ==> 86
W ==> 87
X ==> 88
Y ==> 89
Z ==> 90
>>>
# Create alphabet list of uppercase letters
alphabet = []
for letter in range(65, 91):
alphabet.append(chr(letter))
for i in range (len(alphabet)):
print (alphabet[i],ord(alphabet[i]))
# Create alphabet list of uppercase letters
alphabet = []
for letter in range(65, 91):
alphabet.append(chr(letter))
for i in range (len(alphabet)):
print (alphabet[i],ord(alphabet[i]))
======== RESTART: F:/Python_APSC/py-ex-basic-86-1.py ============
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
>>>
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
>>>
沒有留言:
張貼留言