Remove the specified characters from the beginning and end of the string strip() rstrip()

1. The Python strip() method is used to remove the specified characters from the beginning and end of the string (the default is a space)

#!/usr/bin/python
# -*- coding: UTF-8 -*-

str = "0000000     Runoob  0000000"; 
print str.strip( '0' );  # 去除首尾字符 0
str2 = "   Runoob      ";   # 去除首尾空格
print str2.strip();
# 以上实例输出结果如下:
     Runoob  
Runoob

2. Python rstrip() removes the specified character at the end of the string string (default is space)

#!/usr/bin/python

str = "     this is string example....wow!!!     ";
print str.rstrip();
str = "88888888this is string example....wow!!!8888888";
print str.rstrip('8');
# 输出结果如下:
     this is string example....wow!!!
88888888this is string example....wow!!!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325454233&siteId=291194637