20
loading...
This website collects cookies to deliver better user experience
strip()
function removes any leading and trailing whitespace , including tabs (\t), and returns a new string.rstrip()
function removes any *trailing whitespace * returns a new string that means it eliminates the whitespace at the right side of the string.lstrip()
function removes any *leading whitespace * returns a new string that means it eliminates the whitespace at the left side of the string.strip()
function removes any leading and trailing whitespace , including tabs (\t), and returns a new string.# Leading and trailing whitespaces are removed
text1 = ' Python Programming '
print(text1.strip())
# Remove the whitespace and specified character on
# both leading and trailing end
text3 = ' code its my code '
print(text3.strip(' code'))
# Remove the specified character at
# both leading and trailing end
text2 = 'code its my code'
print(text2.strip('code'))
Python Programming
its my
its my
rstrip()
function removes any *trailing whitespace * and returns a new string that means it eliminates the whitespace at the right side of the string.# Only trailing whitespaces are removed
text1 = ' Python Programming '
print(text1.rstrip())
# Remove the whitespace and specified character at
# trailing end
text2 = ' code its my code '
print(text2.rstrip(' code'))
# Remove the specified character at
# trailing end
text3 = 'code its my code'
print(text3.rstrip('code'))
Python Programming
code its my
code its my
lstrip()
function removes any *leading whitespace * and returns a new string that means it eliminates the whitespace at the left side of the string# Only leading whitespaces are removed
text1 = ' Python Programming '
print(text1.lstrip())
# Remove the whitespace and specified character at
# leading end
text2 = ' code its my code '
print(text2.lstrip(' code'))
# Remove the specified character at
# leading end
text3 = 'code its my code'
print(text3.lstrip('code'))
Python Programming
its my code
its my code