目录
②用法:判断字符串的的所有单词是否首字母(开头)是大写其他为小写。
返回为True值必须满足两个条件:
①至少含有一个区分大小写的字符,即26的英文字母。
②区分大小写的字符必须为小写。
返回为True值必须满足两个条件:
①至少含有一个区分大小写的字符,即26的英文字母。
②区分大小写的字符必须为大写。
解释说明
如果字符串中所有的单词拼写首字母是否为大写,且其他字母为小写则返回 True,否则返回 False
- """islower isupper istitle函数"""
- ##定义string
- string1 = 'ajhj6646'
- string2 = 'hkjdlan'
- string3 = 'JNKljl'
- string4 = 'KJKLMLKK'
- string5 = 'Kjkfhj655'
- string6 = 'How are you?'
- string7 = 'How Are You?'
-
- #判断字符串1
- string1.islower() #输出结果为:TRUE
- string1.isupper() #输出结果为:FALSE
- string1.istitle() #输出结果为:FALSE
- # 解释:因为string1区分大小写的字符全为小写,所以islower函数返回值为True,而isupper和istitle函数返回值为FALSE
-
-
- #判断字符串2
- string2.islower() #输出结果为:TRUE
- string2.isupper() #输出结果为:FALSE
- string2.istitle() #输出结果为:FALSE
- # 解释:因为string2区分大小写的字符全为小写,所以islower函数返回值为True,而isupper和istitle函数返回值为FALSE
-
- #判断字符串3
- string3.islower() #输出结果为:FALSE
- string3.isupper() #输出结果为:FALSE
- string3.istitle() #输出结果为:FALSE
- # 解释:因为string3区分大小写的字符大小写都有,也不是首字母大写其他为小写,所以islower函数、isupper和istitle函数返回值为FALSE
-
- #判断字符串4
- string4.islower() #输出结果为:FALSE
- string4.isupper() #输出结果为:TRUE
- string4.istitle() #输出结果为:FALSE
- # 解释:因为string4区分大小写的字符全为大写,所以isupper函数返回值为True,而islower和istitle函数返回值为FALSE
-
- #判断字符串5
- string5.islower() #输出结果为:FALSE
- string5.isupper() #输出结果为:FALSE
- string5.istitle() #输出结果为:TRUE
- # 解释:因为string5区分大小写的字符开头为大写其他为小写,所以istitle函数返回值为True,而islower和isupper函数返回值为FALSE
-
-
- #判断字符串6
- string6.islower() #输出结果为:FALSE
- string6.isupper() #输出结果为:FALSE
- string6.istitle() #输出结果为:FALSE
- # 解释:因为string6这个句子字符串每个单词不是区分大小写的字符开头为大写其他为小写,也不是全为大写或者全为小写,所以islower函数、isupper和istitle函数返回值为FALSE
-
- #判断字符串7
- string7.islower() #输出结果为:FALSE
- string7.isupper() #输出结果为:FALSE
- string7.istitle() #输出结果为:True
- # 解释:因为string7每个单词区分大小写的字符开头为大写其他为小写,所以istitle函数返回值为True,而islower和isupper函数返回值为FALSE
判断某个字符串是否只含有字母,是则返回bingo,否返回dejectedly。
- str = 'good good study, day day up'
- if str.islower() is True:
- print('lower')
- elif str.isupper() is True:
- print('upper')
- elif str.istitle() is True:
- print('title')
- else:
- print('dejectedly')
-
- #输出结果为lower
判断输入的某个字符串是否只含有字母,是则返回bingo,否返回dejectedly。
- str = input('请输入目标字符串')
- if str.islower() is True:
- print('lower')
- elif str.isupper() is True:
- print('upper')
- elif str.istitle() is True:
- print('title')
- else:
- print('dejectedly')
-
-
- #若输入的值为:jhjkvnm
- #输出结果为:low
- #若输入的值为:HOW TO GO
- #输出结果为:upper
- #若输入的值为:How To Go
- #输出结果为:title
- #若输入的值为:HOW To GO
- #输出结果为:dejectedly
判断某个列表的几个字符串是否只含有字母,是则返回bingo,否返回dejectedly。
- #定义str
- list = ['good good study, day day up','gjhbj2331','Upstairs']
- for str in list:
- if str.islower() is True:
- print('lower')
- elif str.isupper() is True:
- print('upper')
- elif str.istitle() is True:
- print('title')
- else:
- print('dejectedly')
-
-
- #输出结果为:lower
- #lower
- #'title
具体input函数用法可参考文章:python的input函数用法_小白修炼晋级中的博客-CSDN博客_python中input的用法
具体if判断语句用法可参考:python的if条件语句的用法及实例_小白修炼晋级中的博客-CSDN博客_python中if语句的实例