创新互联Python教程:Pythonrstrip()
python 中的rstrip()函数根据给定的参数删除原始字符串副本中的尾随字符。方法将此副本作为输出返回。

 **string.rstrip([chars])** #where chars are those to remove from right 
rstrip()参数:
函数的作用是:将一组字符作为参数。如果未提供字符,则从字符串中删除尾随空格。
| 参数 | 描述 | 必需/可选 | 
|---|---|---|
| 烧焦 | 要作为尾随字符移除的字符 | 可选择的 | 
rstrip()返回值
返回值始终是字符串。在找到第一个匹配之前,所有字符组合都将从右侧开始移除。
| 投入 | 返回值 | | 线 | 字符串的副本 |
Python 中rstrip()方法的示例
示例rstrip()在 Python 中是如何工作的?
 string1 = "     python     "
string2 = string1.rstrip()
print("of all programming languages", string2, "is my favorite") 
输出:
 of all programming languages     python is my favorite 示例 2:在 Python 中使用rstrip()
 # Variable declaration  
string1 = "Python and Java* "  
# Calling function  
string2 = string1.rstrip(*)  
# Displaying result  
print("Before strip: ",string1)  
print("After strip: ",string2) 
输出:
 Before strip:  Python and Java* 
After strip:  Python and Java 当前标题:创新互联Python教程:Pythonrstrip()
标题路径:http://jxruijie.cn/article/cddhgjd.html

 
                