Python字符串 lower() 方法
Python String lower()方法将字符串中的所有大写字符转换为小写字符并返回。
Syntax:
string.lower()
Parameters:
The lower() method doesn’t take any parameters.
Returns:
Returns a lowercase string of the given string
示例 1 :只有字母字符的字符串
Python3
# Python3 program to show the
# working of lower() function
text = 'GeEks FOR geeKS'
print("Original String:")
print(text)
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())
Python3
# Python3 program to show the
# working of lower() function
text = 'G3Ek5 F0R gE3K5'
print("Original String:")
print(text)
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())
Python3
# Python3 program to show the
# working of lower() function
text1 = 'GEEKS For GEEKS'
text2 = 'gEeKS fOR GeeKs'
# Comparison of strings using
# lower() method
if(text1.lower() == text2.lower()):
print("Strings are same")
else:
print("Strings are not same")
输出:
Original String:
GeEks FOR geeKS
Converted string:
geeks for geeks
示例2:带有字母数字字符的字符串
Python3
# Python3 program to show the
# working of lower() function
text = 'G3Ek5 F0R gE3K5'
print("Original String:")
print(text)
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())
输出:
Original String:
G3Ek5 F0R gE3K5
Converted String:
g3ek5 f0r ge3k5
示例 3
lower() 方法的常见应用之一是检查两个字符串是否相同。
Python3
# Python3 program to show the
# working of lower() function
text1 = 'GEEKS For GEEKS'
text2 = 'gEeKS fOR GeeKs'
# Comparison of strings using
# lower() method
if(text1.lower() == text2.lower()):
print("Strings are same")
else:
print("Strings are not same")
输出:
Strings are same