istitle()
方法的语法是
string.istitle()
istitle() 参数
istitle()
方法不接受任何参数。
istitle() 的返回值
istitle()
方法返回
- 如果字符串是标题大小写字符串,则返回
True
- 如果字符串不是标题大小写字符串或空字符串,则返回
False
示例 1:istitle() 的工作原理
s = 'Python Is Good.'
print(s.istitle())
s = 'Python is good'
print(s.istitle())
s = 'This Is @ Symbol.'
print(s.istitle())
s = '99 Is A Number'
print(s.istitle())
s = 'PYTHON'
print(s.istitle())
输出
True False True True False
示例 2:如何使用 istitle()?
s = 'I Love Python.'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
s = 'PYthon'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
输出
Titlecased String Not a Titlecased String
另请阅读