转换成大写函数 - str.upper()
转换成小写函数 - str.lower()
转换成标题函数 - str.title()
msg = 'Welcome to Python world!'
print(msg.upper()) # 大写 WELCOME TO PYTHON WORLD!
print(msg.lower()) # 小写 welcome to python world!
print(msg.title()) # 转换为标题 Welcome To Python World!
msg = 'Welcome to Python world!'
old_list = list(msg)
new_list = []
for c in old_list:
if c >= 'a' and c <= 'z':
new_list.append(chr(ord(c) - 32))
else:
new_list.append(c)
new_msg = ''.join(new_list)
print('原始字符串:{}'.format(msg))
print('大写字符串:{}'.format(new_msg))