新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythoncasefold()
python 中的casefold()函數(shù)通過移除字符串中存在的所有區(qū)分大小寫來幫助將字符串轉(zhuǎn)換為小寫。這類似于casefold()方法,但casefold()更強(qiáng)大、更具攻擊性。

**string.casefold()**
casefold()參數(shù):
casefold()方法不接受任何參數(shù)。這個方法可以在比較兩個字符串時找到更多的匹配,并且可以將更多的字符轉(zhuǎn)換為小寫。
casefold()返回值
返回值始終是字符串。此方法在字符串比較時忽略大小寫。
| 投入 | 返回值 | | 線 | casefolder 字符串 |
Python 中casefold()方法的示例
示例 1:使用casefold()的 Python 小寫轉(zhuǎn)換
string = "HOW ARE YOU"
# print lowercase string
print("After lowercase conversion:", string.casefold())
輸出:
After lowercase conversion: how are you
示例 2:使用casefold()嚴(yán)格轉(zhuǎn)換
string1 = "der Flu?"
string2 = "der Fluss"
# ? is equivalent to ss
if string1.casefold() == string2.casefold():
print('The given strings are equal.')
else:
print('The given strings are not equal.')
輸出:
The given strings are equal. 注意:德語小寫字母已經(jīng)是小寫了,casefold()將其轉(zhuǎn)換為 ss,如果使用lower()方法,它什么也不做。
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:Pythoncasefold()
網(wǎng)頁鏈接:http://www.dlmjj.cn/article/dpocodj.html


咨詢
建站咨詢
