Python字符串istitle()方法

Python字符串istitle()方法检查字符串中所有可大小写的第一个字符是否为大写,所有其他可大小写的字符是否均为小写。

语法

以下是istitle()方法的语法 -

str.istitle()

参数

  • NA

返回值

  • 如果字符串是一个可标题化的字符串,并且至少有一个字符,把单词的第一个字母大写,则该方法返回true。否则返回false

示例

以下示例显示了istitle()方法的用法。

#!/usr/bin/python3


str = "This Is String Example...Wow!!!"
print (str.istitle())

str = "This is string example....wow!!!"
print (str.istitle())

当运行上面的程序,它产生以下结果 -

True
False

上一篇: Python字符串 下一篇: Python列表