美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联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()
标题URL:http://www.zsjierui.cn/article/cddhgjd.html

其他资讯