Python字符串转换为小写字母– str.lower()

We can convert a string to lowercase in Python using str.lower() function. In this short tutorial, we will learn how to convert python string to lowercase.

我们可以使用str.lower()函数将字符串转换为小写。 在这个简短的教程中,我们将学习如何将python字符串转换为小写。

Python字符串转换为小写 (Python String to Lowercase)

Let’s look at a simple example of converting a string to lowercase and print it.

让我们看一个将字符串转换为小写并打印的简单示例。

s = '987abcDEF%$'

print('Lowercase String =', s.lower())
print('Original String =', s)

Output:

输出:

Lowercase String = 987abcdef%$
Original String = 987abcDEF%$

Notice that when we call lower() on a string object, the original string remains unchanged. This function creates another string with lowercase characters and returns it. Special characters and numbers are unchanged because they don’t have uppercase and lowercase versions.

注意,当我们在字符串对象上调用lower()时,原始字符串保持不变。 此函数创建另一个带有小写字符的字符串并返回它。 特殊字符和数字不变,因为它们没有大写和小写版本。

带有用户输入的Python字符串lower() (Python String lower() with user input)

Let’s have a look at another example where we will get the user input and convert it to lowercase string and print it.

让我们看另一个示例,在该示例中,我们将获取用户输入并将其转换为小写字符串并进行打印。

s = input('Please Provide Input String\n')

print('Input String in Lowercase =', s.upper())

print('Original String =', s)

Output:

输出:

Please Provide Input String
Java is Nice!!
Input String in Lowercase = java is nice!!
Original String = Java is Nice!!
GitHub Repository. GitHub存储库中检出完整的python脚本和更多Python示例。

Reference: API Doc

参考: API文档

翻译自: https://www.journaldev.com/23431/python-string-to-lowercase-str-lower

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值