写一个Python函数,用于将字符串中的所有小写字母转化为大写字母。
发布时间:2023-05-27 11:35:55
def convert_to_uppercase(text):
"""
将字符串中的所有小写字母转化为大写字母
:param text: 需要处理的字符串
:return: 转化后的字符串
"""
new_text = ''
for char in text:
# 如果是小写字母,将其转化为大写字母
if char.islower():
new_text += char.upper()
else:
new_text += char
return new_text
# 测试代码
print(convert_to_uppercase('Hello World!')) # HELLO WORLD!
print(convert_to_uppercase('hello world')) # HELLO WORLD
print(convert_to_uppercase('Python For Beginners')) # PYTHON FOR BEGINNERS
