来源:
'https://yuanbao.tencent.com/bot/app/share/chat/rIXbGfFW7lTV','https://yuanbao.tencent.com/bot/app/share/chat/pSPy3BsdeIu0',
'https://yuanbao.tencent.com/bot/app/share/chat/wCEBDsW3rQjG','https://yuanbao.tencent.com/bot/app/share/chat/k83naLLSZd6T',
'https://yuanbao.tencent.com/bot/app/share/chat/zrAdVfnmZpXy','https://yuanbao.tencent.com/bot/app/share/chat/5akNpUxTHj0n',将字符串中的所有大写字符转换为小写
text = "Hello WORLD"
result = text.lower()
print(result) # 输出: hello world将字符串中的所有小写字符转换为大写
text = "Hello World"
result = text.upper()
print(result) # 输出: HELLO WORLD将字符串的首字母大写,其余字母小写
text = "hello WORLD"
result = text.capitalize()
print(result) # 输出: Hello world将字符串中每个单词的首字母大写
text = "hello world of python"
result = text.title()
print(result) # 输出: Hello World Of Python将字符串中的大小写互换
text = "Hello World"
result = text.swapcase()
print(result) # 输出: hELLO wORLDusername = input("请输入用户名: ").lower()
# 统一转换为小写,避免大小写敏感问题
print(f"标准化的用户名: {username}")raw_data = ["Apple", "apple", "APPLE", "aPpLe"]
cleaned_data = [item.lower() for item in raw_data]
print(cleaned_data) # 输出: ['apple', 'apple', 'apple', 'apple']article_title = "introduction to python programming"
formatted_title = article_title.title()
print(formatted_title) # 输出: Introduction To Python Programming方法 | 功能 | 返回值 | 原字符串是否改变 |
|---|---|---|---|
lower() | 全部转换为小写 | 新字符串 | 否 |
upper() | 全部转换为大写 | 新字符串 | 否 |
capitalize() | 首字母大写,其余小写 | 新字符串 | 否 |
title() | 每个单词首字母大写 | 新字符串 | 否 |
swapcase() | 大小写互换 | 新字符串 | 否 |
title()方法可能对带有撇号的单词处理不当(如"it's"会被转换为"It'S")if input_str.lower() == "yes":原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。