python strip()
时间: 2023-10-12 15:06:27 浏览: 40
Python的strip()方法用于删除字符串首尾的指定字符。 该方法通过参数指定要删除的字符,然后返回一个新的字符串,不包含指定字符。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Python:字符串中的方法--strip()](https://blog.csdn.net/weixin_55213653/article/details/119006235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
相关问题
Python strip
Python中的strip()函数是用来去除字符串开头和结尾处的空格或指定字符的函数。如果不指定任何参数,则默认去除字符串开头和结尾处的空格。如果指定了参数,则会去除开头和结尾处的指定字符。
示例代码如下:
```
str1 = " hello world! "
print(str1.strip()) # 输出结果为:hello world!
str2 = "---hello world!---"
print(str2.strip("-")) # 输出结果为:hello world!
```
pythonstrip
strip()函数是Python中的一个字符串方法,用于去除字符串两端的指定字符。在给定的字符串中,strip()函数会删除开头和结尾的指定字符,然后返回新的字符串。[1]
例如,如果我们有一个字符串str = "0000000this is string example....wow!!!0000000",我们可以使用strip()函数去除开头和结尾的0,得到新的字符串"this is string example....wow!!!"。[1]
在Python中,strip()函数的默认参数是空格字符,如果不指定要去除的字符,strip()函数将会删除字符串两端的空格字符。[2]
更多关于strip()函数的使用方法可以参考这个链接:http://www.runoob.com/python/att-string-strip.html。