python 中的istitle()
函數有助於檢查字元串是否有標題。如果是,則返回真,否則返回假。這裡的單詞 titlecased 表示每個單詞的第一個字元是大寫字母,單詞中的其餘字元是小寫字母。
**string.istitle()**
istitle()
參數:
istitle()
方法不接受任何參數。在檢查字元串時,所有符號和數字都被忽略。
istitle()
返回值
返回值始終是布爾值。如果是空字元串、數字字元串或只有符號的字元串,函數將返回 False。
| 投入 | 返回值 |
| 標題大小寫字元串 | 真實的 |
| 不是標題大小寫字元串 | 錯誤的 |
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
原創文章,作者:XNT14,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/130256.html