Python字符串中返回bool类型的函数

目录

isspace

    功能:isspace判断字符串是否是个由空格组成的字符串 用法:booltype = string.isspace () ->无参数可传,返回一个布尔类型
In [31]:  .isspace()
0ut[31]: True
In [32]: hello insane.isspace()
out [32]: False
    Ps:由空格组成的字符串,不是空字符串:"!=,"

istitle

    功能:istitle判断字符串是否是一个标题类型(所有单词全是首字母大写) 用法:booltype = String.istitle() -> 无参数可传,返回一个布尔类型
In [33]: Hello Insane.istitle()
Out[33] : True
In [34]: hello insane.istitle()
Out[34]: False
    Ps:该函数只能用于英文

isupper与islower

    功能: isupper判断字符串中的字母是否都是大写 islower判断字符串中的字母是否都是小写 用法: booltype = string.isupper () ->无参数可传,返回一个布尔类型 booltype = string.islower() ->无参数可传,返回一个布尔类型

实战

# coding:utf-8

title = Back Of China
upper_str = PYTHON IS GOOD CODE
upper_str_01 = PYTHON IS GOOD CODE 哈哈
upper_str_02 = Python Is Good Code
lower_str = i love python
lower_str_01 = i love python 哈哈
not_empty =  

print(title.istitle())
print(upper_str.isupper())
print(upper_str_01.isupper())
print(upper_str_02.istitle())
print(lower_str.islower())
print(lower_str_01.islower())
print(not_empty.isspace())
True
True
True
True
True
True
True

Process finished with exit code 0
经验分享 程序员 微信小程序 职场和发展