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


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


如果字符串是帶有標題的字符串,則istitle()返回True,否則返回False。

標題大小寫是什麽?

在每個單詞中第一個字符為大寫,其餘所有字符為小寫字母的字符串。


用法:

string.istitle()

參數:

The istitle() method doesn’t take any parameters.

返回值:

returns True if the string is a titlecased string otherwise it returns False.

代碼1

# 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

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


相關用法


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