如果字符串是带有标题的字符串,则istitle()返回True,否则返回False。
标题大小写是什么?
在每个单词中第一个字符为大写,其余所有字符为小写字母的字符串。
用法:
string.istitle()
参数:
The istitle() method doesn’t take any parameters.
返回值:
returns True if the string is a titlecased string otherwise it returns False.
代码1
# First character in each word is
# uppercase and remaining lowercases
s = 'Geeks For Geeks'
print(s.istitle())
# First character in first
# word is lowercase
s = 'geeks For Geeks'
print(s.istitle())
# Third word has uppercase
# characters at middle
s = 'Geeks For GEEKs'
print(s.istitle())
s = '6041 Is My Number'
print(s.istitle())
# word has uppercase
# characters at middle
s = 'GEEKS'
print(s.istitle())
输出:
True False False True False
代码2
s = 'I Love Geeks For Geeks'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
s = 'I Love geeks for geeks'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
输出:
Titlecased String Not a Titlecased String
相关用法
注:本文由纯净天空筛选整理自pawan_asipu大神的英文原创作品 Python String | istitle()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。