Python中的 isupper() 函数的作用是检查一个字符串中的字符是否都为大写形式,如果字符串不为空,且所有字符都为大写形式的话就返回 True ,否则返回 False 。
可以认为,Python 的 isupper() 函数的作用与 islower() 函数是相反的。后者的作用是检查一个字符串的所有字符是否都为小写形式。
一、isupper()函数的语法形式
str_name.isupper()
str_name是要检查的字符串或字符串变量;
该函数没有参数;
该函数的返回值是逻辑值:True 或 False.
二、isupper()函数使用示例
1、只包含字母且所有字符都为大写
str1 = "WELCOME TO SHANGHAI"
print(str1.isupper())
str1 = "ΓΔΘΚ" #希腊大写字母
print(str1.isupper())
str1 = "БДЁЖ" #俄文字母
print(str1.isupper())
在Python3.8.2中的执行情况如下图所示:
2、只包含大小写字母
str1 = "Welcome to Hebei"
print(str1.isupper())
str1 = "ΦσΣ"
print(str1.isupper())
输出:
False