In this article, we will go for capitalizing the characters i.e. conversion from lowercase to uppercase without using any function. This article is based on the concept that how inbuilt function perform this task for us?
在本文中,我们将大写字符,即不使用任何功能 将字符 从小写转换为大写 。 本文基于以下概念:内置函数如何为我们执行此任务?
So, let's write a program to perform this task.
因此,让我们编写一个程序来执行此任务。
Key: The difference between the ASCII value of A and a is 32
密钥: A和a的ASCII值之差为32
Example:
例:
Input:
Hello world!
Output:
HELLO WORLD!
Python code to capitalize the character without using a function
Python代码无需使用功能即可大写字符
# Python program to capitalize the character
# without using a function
st = input('Type a string: ')
out = ''
for n in st:
if n not in 'abcdefghijklmnopqrstuvwqxyz':
out = out + n
else:
k = ord(n)
l = k - 32
out = out + chr(l)
print('------->', out)
Output
输出量
First run:
Type a string: Hello world!
-------> HELLO WORLD!
Second run:
Type a string: 12345Hello @123$#
-------> 12345HELLO @123$#
Third run:
Type a string: 82918298198291898A
-------> 82918298198291898A
翻译自: https://www.includehelp.com/python/program-to-capitalize-the-character-without-using-a-function.aspx