Advertisement
rjust(length, padding)
Parameters | Description |
---|---|
length | This is the length of the string returned by the method rjust(). This is a non-optional attribute. |
padding | This value is used as a padding while right justifying the invoked string value. This is an optional attribute. |
# Python - Example of rjust() method
# Creating a string
s1 = ('United Kingdom')
# Printing the original string
print('Value of string : ', s1)
# Calling the rjust() method on string object
print('Calling the rjust() method on string : ', s1.rjust(20))
Value of string : United Kingdom
Calling the rjust() method on string : United Kingdom
# Python -Example of rjust() method
# Creating a string
s1 = ('Moon - The Natural Satellite of Earth')
# Printing the original string
print('Original string before calling rjust() : ', s1)
# Calling the rjust() method on string object
# returns a string object which is right justified with length 40
print('Calling the rjust() method : ', s1.rjust(40))
# Printing the original string
print('Original string after calling rjust() : ', s1)
Original string before calling rjust() : Moon - The Natural Satellite of Earth
Calling the rjust() method : Moon - The Natural Satellite of Earth
Original string after calling rjust() : Moon - The Natural Satellite of Earth
Advertisement
# Python - rjust() method example.
# Creating a string
s = 'Smile as much as you can!'
# Printing the original string
print('Original string is : ', s)
# Result of calling rjust() is made to reference by the reference of original string.
s = s.rjust(50)
# Old reference variable pointing to the new string
print('String value after rjust() method : ', s)
Original string is : Smile as much as you can!
String value after rjust() method : Smile as much as you can!
# Python - rjust() method example.
# Creating a string
s = 'Eat healthy, live healthy!'
# Printing the original string
print('Original string is : ', s)
# Calling the rjust() method on string object
# which will return a right justified value of length 30, padded with a space on its left.
print(s.rjust(30))
# Calling the rjust() method on string object
# which will return a right justified value of length 30, padded with # on its left.
print(s.rjust(30, '#'))
# Calling the rjust() method on string object
# which will return a right justified value of length 40, padded with X on its left.
print(s.rjust(40, 'X'))
# Calling the rjust() method on string object
# which will return a right justified value of length 60, padded with 0 on its left.
print(s.rjust(60, '0'))
# Calling the rjust() method on string object
# which will return a right justified value of length 50, padded with @ on its left.
print(s.rjust(50, '@'))
# Calling the rjust() method on string object
# which will return a right justified value of length 45, padded with @ on its left.
print(s.rjust(45, '.'))
Original string is : Eat healthy, live healthy!
Eat healthy, live healthy!
####Eat healthy, live healthy!
XXXXXXXXXXXXXXEat healthy, live healthy!
0000000000000000000000000000000000Eat healthy, live healthy!
@@@@@@@@@@@@@@@@@@@@@@@@Eat healthy, live healthy!
...................Eat healthy, live healthy!
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement