Python String rjust Method - Python Tutorial | Logic Practice
Python Course / Other / Python String rjust Method

Python String rjust Method

BLUF: This lesson on Python String rjust Method provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python String rjust Method

Mastering Python String rjust Method is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

The rjust method in Python is utilized to align a string to the right, filling any unused space with specified fill characters. This method generates and returns a new string that is right-justified and includes the designated fill characters in the remaining areas.

Syntax of Python String rjust Method

It has the following syntax:

Example

rjust(width[, fillchar])

Parameters

  • width: width of the given string.
  • fillchar: characters to fill the remaining space in the string. It is optional.
  • Return

It returns a right justified string.

Different Examples for Python String rjust Method

Let’s examine a few instances of the rjust method to grasp its functionalities more effectively.

Example 1

In this section, we will illustrate the use of the Python String rjust method through a specific example.

Example

# Python rjust() method example

# Variable declaration

str = 'Example'

# Calling function

str = str.rjust(20)

# Displaying result

print(str)

Output:

j a v a p o i n t

Example 2

In this section, we will illustrate the usage of the Python String rjust Method through a practical example.

Example

# Python rjust() method example

# Variable declaration

str = 'Example'

# Calling function

str = str.rjust(15,"$")

# Displaying result

print(str)

Output:

$ $ $ $ $ j a v a p o i n t

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience