Python中大小写转换的方法 在Python编程中,经常需要对文本进行大小写转换的操作。本文将介绍Python中字符串大小写转换的方法,以及如何使用它们来优化你的代码。 方法一:使用upper()和lower()方法 Python中,可以使用字符串对象的upper()和lower()方法来将字符串转换为大写或小写。 string = "hello WORLD" print(string.upper()) # 输出:HELLO WORLD print(string.lower())