Python String istitle() 方法
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('是首字母大写的字符串')
else:
print('不是首字母大写的字符串')
s = 'PYthon'
if s.istitle() == True:
print('是首字母大写的字符串')
else:
print('不是首字母大写的字符串')
输出
是首字母大写的字符串
不是首字母大写的字符串