how to strip string in python

there is strip function in python.

strip function strips string literally.

there are 3 types of strip.

str.rstrip([chars])
str.lstrip([chars])
str.strip([chars])

the way how to use is all the same but the direction which side will be stripped is different.
chars parameter is characters to be stripped. if none, the default value is whitespace.

I made example code. this will be helpful to understand the operation.


str1 = "       hello python        "
print(str1.rstrip())
print(str1.lstrip())
print(str1.strip())

str2 = "aaaaaaahello pythonbbbbbbbb"
print(str2.lstrip("a"))
print(str2.rstrip("b"))
print(str2.strip("ab"))




Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2