字符串能进行大小写转换吗可以使用哪些方法
字符串可以进行大小写转换。可以使用以下方法:
-
upper():将字符串中的所有字母转换为大写字母。
-
lower():将字符串中的所有字母转换为小写字母。
-
capitalize():将字符串的第一个字母转换为大写字母,其余的字母转换为小写字母。
-
title():将字符串中每个单词的第一个字母转换为大写字母,其余的字母转换为小写字母。
例如:
string = "Hello World"
print(string.upper()) # 输出 "HELLO WORLD"
print(string.lower()) # 输出 "hello world"
print(string.capitalize()) # 输出 "Hello world"
print(string.title()) # 输出 "Hello World"
原文地址: http://www.cveoy.top/t/topic/dx6K 著作权归作者所有。请勿转载和采集!