當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python String istitle()用法及代碼示例

Python String istitle() 方法返回 True 如果字符串是標題字符串,否則返回 False。什麽是冠名?每個單詞的第一個字符為大寫,其餘所有字符為小寫字母的字符串。

用法: 

string.istitle()

參數:

istitle() 方法不帶任何參數。



返回值:

如果字符串是標題字符串,則為 True,否則返回 False。

例子1

Python3


# First character in each word is 
# uppercase and remaining lowercases
s = 'Geeks For Geeks'
print(s.istitle())
  
# First character in first
# word is lowercase
s = 'geeks For Geeks'
print(s.istitle())
  
# Third word has uppercase
# characters at middle
s = 'Geeks For GEEKs'
print(s.istitle())
  
s = '6041 Is My Number'
print(s.istitle())
  
# word has uppercase
# characters at middle
s = 'GEEKS'
print(s.istitle())

輸出:

True
False
False
True
False

例子2

Python3


s = 'I Love Geeks For Geeks'
  
if s.istitle() == True:
    print('Titlecased String')
else:
    print('Not a Titlecased String')
  
s = 'I Love geeks for geeks'
  
if s.istitle() == True:
    print('Titlecased String')
else:
    print('Not a Titlecased String')

輸出:

Titlecased String
Not a Titlecased String




相關用法


注:本文由純淨天空篩選整理自GeeksforGeeks大神的英文原創作品 Python String istitle() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。