十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
python 中的rstrip()函数根据给定的参数删除原始字符串副本中的尾随字符。方法将此副本作为输出返回。

**string.rstrip([chars])** #where chars are those to remove from right
rstrip()参数:函数的作用是:将一组字符作为参数。如果未提供字符,则从字符串中删除尾随空格。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 烧焦 | 要作为尾随字符移除的字符 | 可选择的 |
rstrip()返回值返回值始终是字符串。在找到第一个匹配之前,所有字符组合都将从右侧开始移除。
| 投入 | 返回值 | | 线 | 字符串的副本 |
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
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