小白教程
所有教程
关于
Search
172.70.179.121
172.70.179.121
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 string rstrip”的源代码
本页内容
上一节:
Python3_string_rjust
下一节:
Python3_string_split
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:rstrip()}}[[Category:python3 string|30]] = Python3 rstrip() 方法 = [[python3 string|Python3 字符串]] == 描述 == rstrip() 删除 string 字符串末尾的指定字符,默认为空白符,包括空格、换行符、回车符、制表符。 == 语法 == rstrip()方法语法: <sample title="" desc="" lang="python" hererun="1"> str.rstrip([chars]) </sample> == 参数 == * chars -- 指定删除的字符(默认为空白符) == 返回值 == 返回删除 string 字符串末尾的指定字符后生成的新字符串。 以下实例展示了 rstrip() 函数的使用方法: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 random_string = 'this is good ' # 字符串末尾的空格会被删除 print(random_string.rstrip()) # 'si oo' 不是尾随字符,因此不会删除任何内容 print(random_string.rstrip('si oo')) # 在 'sid oo' 中 'd oo' 是尾随字符,'ood' 从字符串中删除 print(random_string.rstrip('sid oo')) # 'm/' 是尾随字符,没有找到 '.' 号的尾随字符, 'm/' 从字符串中删除 website = 'www.xiaobai.wang/' print(website.rstrip('m/.')) # 移除逗号(,)、点号(.)、字母 s、q 或 w,这几个都是尾随字符 txt = "banana,,,,,ssqqqww....." x = txt.rstrip(",.qsw") print(x) # 删除尾随字符 * str = "*****this is string example....wow!!!*****" print (str.rstrip('*')) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> this is good this is good this is g www.xiaobai.co banana *****this is string example....wow!!! </sample> [[python3 string|Python3 字符串]]
返回至“
Python3 string rstrip
”。
上一节:
Python3_string_rjust
下一节:
Python3_string_split