Advertisement
# Signature of rstrip() method
rstrip()
# Python - Program to strip the trailing blank spaces from a string using rstrip() method
# Creating a first string with trailing white spaces
s1 = 'hello '
# Creating a string with no trailing white spaces
s2 = ' there'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Calling the rstrip() method on string object
print('The trimmed value of first string : ', s1.rstrip())
# Creating a third string by concatenating trimmed form of string with another string, using + operator
s3 = s1.rstrip() + s2
# Printing the third string
print('The value of third string : ', s3)
The value of first string : hello
The value of second string : there
The trimmed value of first string : hello
The value of third string : hello there
Advertisement
# Python - Method rstrip() does not modify the invoked string
# Creating a first string with trailing white spaces
s1 = 'humpty '
# Creating a string with no trailing white spaces
s2 = 'dumpty'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Calling the rstrip() method on string object
print('The trimmed value of first string : ', s1.rstrip())
# Creating a third string by concatenating the first string with second, using + operator
s3 = s1 + s2
# Printing the third string
print('The value of third string : ', s3)
The value of first string : humpty
The value of second string : dumpty
The trimmed value of first string : humpty
The value of third string : humpty dumpty
#Python - Another example of rstrip() method
# Creating the first string
s1 = 'A good smile '
# Creating the second string
s2 = ' changes everything'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Result of calling rstrip() is made to reference by the reference of original string.
s1 = s1.rstrip()
# Creating a third string by concatenating the first string with second, using + operator
s3 = s1 + s2
# Printing the third string
print('Third string by contenating first and second string : ', s3)
The value of first string : A good smile
The value of second string : changes everything
Third string by contenating first and second string : A good smile changes everything
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement