新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonstrip()
python 中的strip()函數(shù)根據(jù)給定的參數(shù)刪除原始字符串副本中的尾隨和前導(dǎo)字符。方法將此副本作為輸出返回。

**string.strip([chars])** #where chars are those to remove from right & left
條帶()參數(shù):
strip()函數(shù)將一組字符作為其參數(shù)。如果未提供字符,則從字符串中刪除尾隨空格和前導(dǎo)空格。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 燒焦 | 要作為尾隨和前導(dǎo)字符移除的字符 | 可選擇的 |
條帶()返回值
返回值始終是字符串。在找到第一個(gè)匹配之前,它從字符串的左側(cè)和右側(cè)進(jìn)行搜索,如果到達(dá)字符串的末尾,它將停止移除。
| 投入 | 返回值 | | 線 | 字符串的副本 |
Python 中strip()方法的示例
示例strip()在 Python 中是如何工作的?
string1 = ",,,,,rrttgg.....python....rrr"
# Removing characters
string2 = string1.strip(",.grt")
print(string2)
輸出:
python
示例strip()如何刪除兩邊的空白?
string1 = " Hii Python! "
# Removes white spaces
after_strip = string1.strip()
輸出:
Hii Python! 網(wǎng)站標(biāo)題:創(chuàng)新互聯(lián)Python教程:Pythonstrip()
文章起源:http://fisionsoft.com.cn/article/cocpddp.html


咨詢
建站咨詢
