Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




rjust( ) FUNCTION


rjust( ) Function


The rjust( ) Function is used to right justify a String using Space by default.


Example :


x = "Hello"
y = x.rjust(10)
print(y)


Output :



   Hello

In the above code, we have declared a String 'Hello' and assigned it to a variable 'x'.


x = "Hello"

java_Collections

Then we have created a variable 'y' that will reserve '10' blocks. And right justified the String 'Hello' using 'rjust( )' Function.


y = x.rjust(10)

That shifts the String Hello towards the right filling the first 5 locations with space (i.e. ' ').


java_Collections

Now, let us say you want the fill the left blocks with something other than spaces.


And luckily, Python provides a second parameter that can be used as a padding character.


Let us see with the below example.


Example :


x = "Hello"
y = x.rjust(10, "*")
print(y)


Output :



  *****Hello

In the above code, we have declared a String 'Hello' and assigned it to a variable 'x'.


x = "Hello"

java_Collections

Then we have created a variable 'y' that will reserve '10' blocks. And right justified the String 'Hello' using 'rjust( )' Function.


y = x.rjust(10, "*")

That shifts the String Hello towards the right filling the first 5 locations with asterisk (i.e. '*').


java_Collections