新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonistitle()
python 中的istitle()函數(shù)有助于檢查字符串是否有標(biāo)題。如果是,則返回真,否則返回假。這里的單詞 titlecased 表示每個單詞的第一個字符是大寫字母,單詞中的其余字符是小寫字母。

**string.istitle()**
istitle()參數(shù):
istitle()方法不接受任何參數(shù)。在檢查字符串時,所有符號和數(shù)字都被忽略。
istitle()返回值
返回值始終是布爾值。如果是空字符串、數(shù)字字符串或只有符號的字符串,函數(shù)將返回 False。
| 投入 | 返回值 | | 標(biāo)題大小寫字符串 | 真實的 | | 不是標(biāo)題大小寫字符串 | 錯誤的 |
Python 中istitle()方法的示例
示例 1:istitel()在 Python 中是如何工作的?
string = 'Hi How Are You'
print(string.istitle())
string = 'Hi how are you'
print(string.istitle())
string = 'Hi How Are You?'
print(string.istitle())
string = '121 Hi How Are You'
print(string.istitle())
string = 'HOW ARE YOU'
print(string.istitle())
輸出:
True
False
True
True
False
示例 2:如何在 Python 中使用istitle()?
string = 'Python programming'
if string.istitle() == True:
print('It is a Titlecased String')
else:
print('It is not a Titlecased String')
string = 'PYthon PRogramming'
if string.istitle() == True:
print('It is a Titlecased String')
else:
print('It is not a Titlecased String')
輸出:
It is a Titlecased String
It is not a Titlecased String 本文題目:創(chuàng)新互聯(lián)Python教程:Pythonistitle()
文章地址:http://www.dlmjj.cn/article/cdpchdd.html


咨詢
建站咨詢
