rjust()

Add right justified filler strings of specified width
my_string.rjust(width, filler)
width : right justified string of width
filler : (optional) string can be used to fill the width
my_str='Welcome to'
output=my_str.rjust(15,' ')
print(output, 'plus2net')
Output
     Welcome to plus2net
my_str='Welcome to'
output=my_str.rjust(15,'#')
print(output, 'plus2net')
Output
#####Welcome to plus2net

Example for Data Alignment with rjust()

# Aligning data in table format
header1 = "Name"
header2 = "Score"
print(header1.rjust(10) + header2.rjust(10))

data = [("Alice", 95), ("Bob", 87), ("Charlie", 92)]
for name, score in data:
    print(name.rjust(10) + str(score).rjust(10))
output
      Name     Score
     Alice        95
       Bob        87
   Charlie        92
Example : Right-Justify with Custom Padding
text = "Python"
print(text.rjust(10, '*'))  # Output: ****Python
print(text.rjust(12, '-'))  # Output: ------Python

Example : Aligning Data in a Table

header1 = "Item"
header2 = "Price"
print(header1.rjust(10) + header2.rjust(10))

items = [("Apple", 2.5), ("Banana", 1.1), ("Cherry", 3.2)]
for item, price in items:
    print(item.rjust(10) + str(price).rjust(10))
output
      Item     Price
     Apple       2.5
    Banana       1.1
    Cherry       3.2
All String methods ljust()


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer