Python 中的 rstrip()函数

首页 / Python2入门教程 / Python 中的 rstrip()函数

Python rStrip()返回字符串的副本,其中所有字符都已从字符串的末尾剥离(默认空格字符)。

rstrip() - 语法

str.rstrip([chars])
  • chars  -  您可以提供必须修剪的字符。

rstrip() - 返回值

此方法返回字符串的副本,其中所有字符都已从字符串的末尾剥离(默认空格字符)。

rstrip() - 示例

以下示例显示了rStrip()方法的用法。

#!/usr/bin/python

str="     this is string example....wow!!!     ";
print str.rstrip()
str="88888888this is string example....wow!!!8888888";
print str.rstrip('8')

当无涯教程运行上面的程序时,它产生以下输出-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/python/string-rstrip.html

来源:LearnFk无涯教程网

this is string example....wow!!!
88888888this is string example....wow!!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

技术领导力实战笔记 -〔TGO鲲鹏会〕

玩转webpack -〔程柳锋〕

雷蓓蓓的项目管理实战课 -〔雷蓓蓓〕

Web安全攻防实战 -〔王昊天〕

Selenium自动化测试实战 -〔郭宏志〕

Linux内核技术实战课 -〔邵亚方〕

容器实战高手课 -〔李程远〕

如何成为学习高手 -〔高冷冷〕

eBPF核心技术与实战 -〔倪朋飞〕

好记忆不如烂笔头。留下您的足迹吧 :)