74 of 151 menu

The rjust method

The rjust method returns a string in which the text is filled and aligned to the right. In the first parameter of the method we pass a number to determine the length of the string, in the second optional parameter - a filler character, by default it is a space.

Syntax

string.rjust(stringlength, [placeholder symbol])

Example

Let's apply the rjust method to our string, and specify an exclamation mark as the placeholder:

txt = 'abc' print(txt.rjust(6, '!'))

Result of code execution:

'!!!abc'

Example

Let's apply the ljust method to our string without specifying a placeholder:

txt = 'abc' print(txt.ljust(6))

Result of code execution:

' abc'

See also

  • method ljust,
    which aligns and fills the text in a line to the left
  • method zfill,
    which fills the beginning of the string with zeros
  • function len,
    which returns the length of the string
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline