当前位置:首页python > 正文

python大小写字母转换

作者:野牛程序员:2023-11-07 14:36:33python阅读 2681

Python中大小写字母的转换可以使用以下方法:

  1. 将字符串中的所有字符转换为小写字母:

string = "Hello World"
string.lower()
  1. 将字符串中的所有字符转换为大写字母:

string = "Hello World"
string.upper()
  1. 将字符串中的首字母转换为大写:

string = "hello world"
string.capitalize()
  1. 将字符串中每个单词的首字母转换为大写:

string = "hello world"
string.title()
  1. 交换字符串中的大小写字母:

string = "Hello World"
string.swapcase()

这些方法可以用于字符串大小写字母的转换。


野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892
野牛程序员教少儿编程与信息学竞赛-微信|电话:15892516892
相关推荐

最新推荐

热门点击