一键转换大小写

老A 外汇行情 1

当然可以,以下是一个简单的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环境中运行,根据需要传入不同的字符串和转换方向(大写或小写)。

上一篇1999年5角硬币值钱吗

下一篇当前分类已是最新一篇