python 将空字符串视为大写还是小写?
Does python see an empty string as uppercase or lowercase?
很尴尬,我们有很多关于以下所有标签的问题:
uppercase python lowercase empty-string,但毫无疑问 python 将空字符串视为大写还是小写。那么,python 将空字符串视为大写还是小写?
如果你运行这个:
empty = ""
if empty.islower():
print("The empty string is lowercase")
elif empty.isupper():
print("The empty string is uppercase")
else:
print("The empty string is neither!")
你应该得到:
The empty string is neither!
这是因为 isupper
首先检查是否有多个字符,然后再继续检查其大小写 (look here):
Python isupper is one of the Python String Method used to check whether the given string has at least one character, and the character is either in uppercase or not. If it is in Uppercase, then the Python isupper function returns True; otherwise, it returns False.
很尴尬,我们有很多关于以下所有标签的问题: uppercase python lowercase empty-string,但毫无疑问 python 将空字符串视为大写还是小写。那么,python 将空字符串视为大写还是小写?
如果你运行这个:
empty = ""
if empty.islower():
print("The empty string is lowercase")
elif empty.isupper():
print("The empty string is uppercase")
else:
print("The empty string is neither!")
你应该得到:
The empty string is neither!
这是因为 isupper
首先检查是否有多个字符,然后再继续检查其大小写 (look here):
Python isupper is one of the Python String Method used to check whether the given string has at least one character, and the character is either in uppercase or not. If it is in Uppercase, then the Python isupper function returns True; otherwise, it returns False.