Answers for "strip() function"

25

python strip

# removes outside whitespace/characters
'  hey  '.strip()     # "hey"
'  hey  '.lstrip()    # "hey  "
'  hey  '.rstrip()    # "  hey"
'_.hey__'.strip('._') # "hey"
Posted by: Guest on August-05-2020
1

python strip()

a = "  smurf   "

a = a.strip()
#remove space at begining and end of string
print(a)
#smurf
Posted by: Guest on January-19-2021
0

strip() function

# 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'))
Posted by: Guest on September-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language