Python-python将空字符串视为大写还是小写?

问题描述 投票:-1回答:1

令人尴尬的是,我们对以下所有标签有很多疑问:,但毫无疑问,python是将空字符串视为大写还是小写。那么,python会将空字符串视为大写还是小写?

python string uppercase lowercase
1个回答
0
投票

如果运行此:

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;否则,返回true。否则,它返回False。

© www.soinside.com 2019 - 2024. All rights reserved.