Advertisement
# Signature of strip() method
strip()
# Python - Program to strip the leading and trailing blank spaces from a string by calling the strip() method
# Creating the first string
s1 = ' hello '
# Printing the first string
print('The value of string : ', s1)
# Calling the strip method on string object
print('The stripped value of first string : ', s1.strip())
# Creating the second string
s2 = ' Do not give up '
# Printing the second string
print('The value of string : ', s2)
# Calling the strip method on string object
print('The stripped value of second string : ', s2.strip())
The value of string : hello
The strippedvalue of first string : hello
The value of string : Do not give up
The strippedvalue of second string : Do not give up
#Python - Method strip() does not modify the invoked string
# Creating a string
s1 = ' Lean something new everyday '
# Printing the original string
print('The value of string : ', s1)
# Calling the strip method on string object
print('The strippedvalue of string : ', s1.strip())
# Printing the original string after calling strip method on it.
print('The value of string value : ', s1)
The value of string : Lean something new everyday
The stripped value of string : Lean something new everyday
The value of string value : Lean something new everyday
Advertisement
#Python - Another example of string() method
# Creating a string
s1 = ' you will never have this day again, so make the most out of it! '
# Printing the original string
print('The value of string : ', s1)
# Result of calling strip() is made to reference by the reference of original string.
s1 = s1.strip()
# Old reference variable pointing to the new string
print('The stripped value of the string : ', s1)
The value of string : you will never have this day again, so make the most out of it!
The stripped value of the string : you will never have this day again, so make the most out of it!
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement