Python程序不使用函数将字符大写

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值