Python字符串swapcase() |
您所在的位置:网站首页 › python中swapcase函数的用法 › Python字符串swapcase() |
Python String swapcase() function returns a new string with uppercase characters converted to lowercase and vice versa. Python String swapcase()函数返回一个新字符串,其中大写字符转换为小写,反之亦然。 Python字符串swapcase() (Python String swapcase())This function doesn’t accept any parameter. Note that it’s not necessarily True that s.swapcase().swapcase() == s. 此函数不接受任何参数。 请注意s.swapcase().swapcase() == s不一定是True。 Let’s look at some examples of swapcase() function. 让我们看一下swapcase()函数的一些示例。 s = 'hello' print(s.swapcase()) s = 'HellO' print(s.swapcase())Output: 输出: HELLO hELLoLet’s look at an example with special Unicode characters. 让我们看一个带有特殊Unicode字符的示例。 s = 'çå†' print(s.swapcase()) print(s.swapcase().swapcase()) print(s.swapcase().swapcase() == s)Output: 输出: Çņ çå† TrueNote that not every character has Lowercase and Uppercase version. For example, ‘†’ character doesn’t have Uppercase or Lowercase version. 请注意,并非每个字符都有小写和大写版本。 例如,“†”字符没有大写或小写版本。 Finally, let’s look at an example where s.swapcase().swapcase() == s returns False. 最后,让我们看一个s.swapcase().swapcase() == s返回False的示例。 s = 'ß' # German lowercase letter 'ß' is equivalent to "ss" print(s.swapcase()) print(s.swapcase().swapcase()) print(s.swapcase().swapcase() == s)Output: 输出: SS ss False GitHub Repository. GitHub存储库中签出更多Python示例。Official Documentation: swapcase() 官方文档: swapcase() 翻译自: https://www.journaldev.com/24413/python-string-swapcase |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |