Exercise 51
Using ascii code, write a python program that returns and displays the list of all uppercase characters [A, B, C, ..., Z] and the list of all lowercase characters [a, b, c,. .., z]
Solution
- The ascii codes for the characters A, B, C, ... , Z are: 65 , 66 , ..., 90
- The ascii codes for the characters a, b, c, ... , z are: , 97 ,98 ..., 122
- To get a character from ascii code we use the chr() method. Then:
list_uppercase_characters = [chr(i) for i in range(65 , 91)]
list_lowercae_characters = [chr(i) for i in range(97 , 122)]
print("The list of uppercase characters is : " , list_uppercase_characters)
print("The list of lowercase characters is : " , list_lowercae_characters)
#The output is :
"""
The list of uppercase characters is : ['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']
The list of lowercase characters is : ['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']
"""
Younes Derfoufi
my-courses.net
my-courses.net