Python 字符串 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('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

另请阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战