进行大小写转换的函数类型
upper():所有字母大写
lower():所有字母小写
capitalize():首字母大写,其他字母小写
title():每个单词首字母大写,其他小写
Python中大小写字母编号
Python可根据字母编号判断字母大小写,A的编号为:65,大写字母Z的编号为90,小写字母a的编号为:97,小写字母z的编号为122;大小写字母之间的编号相差32
示例
msg='www.BAIDU.com.123'
for num in msg:
if 97 <= ord(num) <= 122:
upper_num=ord(num)-32
print(chr(upper_num),end="")
elif 65 <= ord(num) <=90:
lower_num=ord(num)+32
print(chr(lower_num),end="")
else:
print(num,end="")
结果
WWW.baidu.COM.123