租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

python upper函数如何使用,python uppercase函数

发布时间:2023-10-14 00:37:02

python upper函数如何使用

Python中的upper()函数用于将字符串中的小写字母转换为大写字母。使用方法以下:

string.upper()

其中,string是要转换为大写字母的字符串。函数将返回一个新的字符串,其中所有的小写字母都被转换为大写字母。原始字符串本身不会被修改。以下是一个示例:

string = "Hello World"
new_string = string.upper()
print(new_string)  # 输出:HELLO WORLD
print(string)  # 输出:Hello World

上述示例中,upper()函数将string字符串中的所有小写字母转换为大写字母,并将结果存储在new_string变量中。原始字符串string保持不变。