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