To do this task, we will use the concepts of ASCII value. ASCII stands for the American Standards Code for Information exchange. It provides us the numerical value for the representation of characters. The ASCII value of uppercase letters and lowercase alphabets start from 65 to 90 and 97-122 respectively. Before going to solve this problem, we will learn a little bit about how to convert the numerical value to characters and vice-versa.
为此,我们将使用ASCII value的概念。 ASCII代表美国信息交换标准代码。 它为我们提供了代表字符的数值。 大写字母和小写字母的ASCII值分别从65到90和97-122开始。 在解决此问题之前,我们将学习一些有关如何将数值转换为字符,反之亦然的知识。
Convert character to numerical value
将字符转换为数值
In Python, a function ord() is used to convert the characters into a numerical value. This is an inbuilt function. Let's see the program,
在Python中, 函数ord()用于将字符转换为数值。 这是一个内置功能。 让我们看一下程序,
# input a number
s=input('Enter the character: ')
# getting its ascii value
n=str(ord(s))
# printing the result
print('ASCII of character {} is {}.'.format(s,n))
Output
输出量
Enter the character: M
ASCII of character M is 77.
Convert numerical value to character
将数值转换为字符
In Python, a function chr() is used to convert a numerical value into character. This is an inbuilt function. Let's see the program,
在Python中, 函数chr()用于将数值转换为字符。 这是一个内置功能。 让我们看一下程序,
# input a number i.e. ascii code
n=int(input('Enter the numerical value: '))
# getting its character value
s=chr(n)
# printing the result
print('The character value of {} is {}.'.format(s,str(n)))
Output
输出量
Enter the numerical value: 77
The character value of M is 77.
Now we have learned how to convert the numerical value into character and by using its concepts we will easily solve the above problem by using the Python language.
现在,我们已经学习了如何将数值转换为字符,并通过使用其概念,可以使用Python语言轻松解决上述问题。
Python程序可打印所有大写和小写字母 (Python program to print the all uppercase and lowercase alphabets)
# printing all uppercase alphabets
print("Uppercase Alphabets are:")
for i in range(65,91):
''' to print alphabets with seperation of space.'''
print(chr(i),end=' ')
# printing all lowercase alphabets
print("\nLowercase Alphabets are:")
for j in range(97,123):
print(chr(j),end=' ')
Output
输出量
Uppercase Alphabets are:
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
Lowercase Alphabets are:
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
翻译自: https://www.includehelp.com/python/print-the-all-uppercase-and-lowercase-alphabets.aspx