Python 字符串 istitle() 方法

定义和用法

如果文本中的所有单词均以大写字母开头,而单词的其余部分均为小写字母,则 istitle() 方法返回 True。否则返回 False。

符号和数字将被忽略。

实例

例子 1

检查每个单词是否以大写字母开头:

txt = "Hello, And Welcome To My World!"

x = txt.istitle()

print(x)

运行实例

例子 2

检查每个单词是否以大写字母开头:

a = "HELLO, AND WELCOME TO MY WORLD"
b = "Hello"
c = "22 Names"
d = "This Is %'!?"

print(a.istitle())
print(b.istitle())
print(c.istitle())
print(d.istitle())

运行实例

语法

string.istitle()

参数值

无参数。