当然可以,以下是一个简单的Python函数,它可以将输入的字符串中的所有字母转换为大写或小写:
```python
def convert_case(text, to_upper=True):
if to_upper:
return text.upper()
else:
return text.lower()
使用示例
input_text = "Hello, World!"
upper_text = convert_case(input_text, to_upper=True) 转换为大写
lower_text = convert_case(input_text, to_upper=False) 转换为小写
print(upper_text) 输出: HELLO, WORLD!
print(lower_text) 输出: hello, world!
```
你可以将上述代码复制到Python环境中运行,根据需要传入不同的字符串和转换方向(大写或小写)。
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。