rstrip strip
时间: 2023-10-24 22:29:52 浏览: 45
rstrip()和strip()是Python中字符串的两个方法,用于去除字符串中的指定字符。
strip()函数用于去除字符串或者字段前后的空格。它可以删除字符串开头和结尾的空格,可以删除字符串开头和结尾的指定字符。如果没有指定参数,默认删除字符串开头和结尾的空格。
而rstrip()函数则用于删除字符串末尾的指定字符,默认删除末尾的空格。它只能删除字符串末尾的字符,不能删除开头的字符。
例如,如果我们有一个字符串str1 = " I love you three thousand times!!! ",我们可以使用strip()函数去除字符串开头和结尾的空格和指定字符,如str1.strip().strip("!stI").strip(),得到的结果是"love you three thousand times"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python中 rstrip() 的用法 以及和 strip() 的区别](https://blog.csdn.net/qq_41800366/article/details/88081034)[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_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Python中 rstrip()、 lstrip()、 strip() 的用法和区别](https://blog.csdn.net/qq_40379132/article/details/124780400)[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_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)