Python upper()

str.upper():将字符串中区分大小写的字符全部转为大写

定义

str.upper()

返回值

将字符串中区分大小写的字符全部转为大写

示例

string = 'HeLlO,21Yi.com'
string2 = "H5i4gup6XdR6Ejau"

print(string, "str.upper(): ", string.upper())
print(string2, "str.upper(): ", string2.upper())

执行结果为 :

HeLlO,21Yi.com str.upper():  HELLO,21YI.COM
H5i4gup6XdR6Ejau str.upper():  H5I4GUP6XDR6EJAU
text1 = '21yI.COm'
text2 = '21YI.cOM'

# Comparison of strings using
# upper() method
if text1.upper() == text2.upper():
    print("Strings are same")
else:
    print("Strings are not same")

执行结果为 :

Strings are same