Python - Print Characters from A to Z
Print Characters from A to Z
To print characters from A to Z (capital alphabets), we can use a loop to iterate from the ASCII value of A to that of Z, and print each character.
Check if Given String is Palindrome
In this example, we write a function that prints uppercase characters from A to Z. We use ord() builtin function to get the ASCII value of a character, and chr() builtin function to convert ASCII to character/string.
Python Program
def printAtoZ():
for i in range(ord('A'), ord('Z') + 1):
print(chr(i))
printAtoZ()
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
We can also generalise this function to print characters from one given point to another given point in ASCII table. The modified function is as shown in the following.
Python Program
def printAtoZ(input1, input2):
for i in range(ord(input1), ord(input2) + 1):
print(chr(i))
printAtoZ('a', 'k')
Output
a
b
c
d
e
f
g
h
i
j
k
Summary
In this Python Examples tutorial, we learned how to print characters from A to Z, or from a given ASCII point to another ASCII point.