📜  Python字符串| istitle

📅  最后修改于: 2020-07-08 01:01:48             🧑  作者: Mango

如果字符串是带有标题的字符串,则istitle()返回True,否则返回False。

标题大小写是什么?

在每个单词中第一个字符为大写,其余所有字符为小写字母的字符串。

 

句法 :string.istitle()

参数:istitle()方法不带任何参数。

返回值:如果字符串是带标题的字符串,则返回True,否则返回False。

 

代码1

# 每个单词的第一个字符为大写字母,其余为小写字母 
s = 'Geeks For Geeks'
print(s.istitle()) 
  
# 第一个单词的第一个字符为小写 
s = 'geeks For Geeks'
print(s.istitle()) 
  
# 第三个单词中间有大写字母 
s = 'Geeks For GEEKs'
print(s.istitle()) 
  
s = '6041 Is My Number'
print(s.istitle()) 
  
# 单词中间有大写字母 
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