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)
str = "0000000 Runoob 0000000";
print str.strip( '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!!!