Python Rjust String Method

Опубликовано: 02 Октябрь 2015
на канале: Code master
6,187
79

Check out the latest version of this tutorial at https://www.mastercode.online/courses...
Be sure to like, share and comment to show your support for our tutorials.

=======================================
Channel - https://goo.gl/pnKLqE
Playlist For This Tutorial - https://goo.gl/EyZFti
Latest Video - https://goo.gl/atWRkF
Facebook -   / mastercodeonline  
Twitter - https://twitter.com/mastercodeonlin?l...
Website - http://mastercode.online
======================================
Python Rjust String Method
Python Rjust String Method
In this Python tutorial, we look at the Python rjust string method. The rjust string method will align the string object to right which is referred right justify. The rjust string method takes a mandatory argument which is how many index spots you would like your new string object to span. The rjust string method also takes an optional argument which is the character fill argument this argument will the white space on the side of the string object. If we do not declare the character fill argument then Python will return the white space on the left side of the string object.

Python Rjust String Method Syntax
'String Object'.rjust(index spots, 'charfill')

'String Object' - This is the string object that will be right justified by the rjust string method.
.rjust() - The rjust string method will justify a string object to the right.
index spots - This mandatory argument instructs the rjust string method to spend a certain amount of index spots.
charfill - This is an optional argument which must be in a string format. This argument enables us to choose which characters we want to use to fill the empty index spots. If we do not include this argument the charfill will revert to white space.
Examples Of The Python Rjust String Method
#Example 1
'This is our string'.rjust(50)
' This is our string'

#Example 2
'Our String'.rjust(30, '%')
'%%%%%%%%%%%%%%%%%%%%Our String'

#Example 3
'Our String'.rjust(10)
'Our String'
Examples Explained

Example 1:

'This is our string'.rjust(50) - We create a new string object and call the rjust string object on our string object. We give our rjust string method an argument of 50 so our new string object will span 50 index spots and the previous string will be positioned to the right.

' This is our string' -We are returned a new string object that spans 50 index spots and our previous string is positioned to the right of the new string object.

Example 2:

'Our String'.rjust(30, '%') - We create a new string object and call the rjust string method on the string object. We provide our rjust string method with an argument of 30 index spots and then we provide another argument of '%' to indicate that we want our spaces to be filled with the '%' symbol.

'%%%%%%%%%%%%%%%%%%%%Our String' - We are returned a new string object that contains our previous string justified to the right and our default spaces filled with '%'.

Example 3:

'Our String'.rjust(10) - We create a new string object and we call the rjust string method on our object. We provide one argument of 10 which is actually smaller than the length of our string.

'Our String' - We are returned a new string that looks like our old string. When we provide an index spaces argument that is equal or smaller to our string we are just returned a new string that is the same as the old string.

Conclusion

In this Python tutorial we learned about the Python rjust string method. If you have any questions about the rjust string method leave a comment below.


На этой странице сайта вы можете посмотреть видео онлайн Python Rjust String Method длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Code master 02 Октябрь 2015, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 6,187 раз и оно понравилось 79 зрителям. Приятного просмотра!