【问题标题】:Does python see an empty string as uppercase or lowercase?python 是否将空字符串视为大写或小写?
【发布时间】:2020-04-29 02:30:45
【问题描述】:
【问题讨论】:
标签:
uppercase
python
lowercase
empty-string
python
string
uppercase
lowercase
【解决方案1】:
如果你运行这个:
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 是 Python 字符串方法之一,用于检查给定字符串是否至少包含一个字符,并且该字符是否为大写。如果是大写,则 Python isupper 函数返回 True;否则返回 False。