Advertisement
endswith(length, padding)
Parameters | Description |
---|---|
length | This is the length of the string returned by the method ljust(). A non-optional attribute. |
padding | This value is used as a padding while left justifying the invoked string value. An optional attribute. |
# Python - Program to left justify the content of a string using ljust() method
# Creating a first string
s1 = 'BONJOUR'
# Creating a second string
s2 = 'à tous'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Creating a third string by concatenating the left justified form of first string with the second string, using + operator
s3 = s1.ljust(15) + s2
# Printing the third string
print('The value of third string : ', s3)
The value of first string : BONJOUR
The value of second string : à tous
The value of third string : BONJOUR à tous
# Python - Program to left justify the content of a string using ljust() method
# Creating a first string
s1 = 'BONJOUR'
# Creating a second string
s2 = ' à tous'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Calling the ljust() method on string object to left justify its content
# And have its length to 30, which is padded with a default space character on its right.
print('The left justified value of first string : ', s1.ljust(30))
# Creating a third string by concatenating the first and the second string, using + operator
s3 = s1 + s2
# Printing the third string
print('Concatenation of first and second string : ', s3)
The value of first string : BONJOUR
The value of second string : à tous
The left justified value of first string : BONJOUR
Concatenation of first and second string : BONJOUR à tous
# Creating a first string
s1 = 'BONJOUR'
# Creating a second string
s2 = ' à tous'
# Printing the first string
print('The value of first string : ', s1)
# Printing the second string
print('The value of second string : ', s2)
# Calling the ljust() method on string object to left justify its content
# And have its length to 20, which is padded with a default space character on its right.
# The result of calling ljust() is assigned to the reference of original string.
s1 = s1.ljust(20)
# Creating a third string by concatenating the first and the second string, using + operator
s3 = s1 + s2
# Printing the third string
print('Concatenation of first and second string : ', s3)
The value of first string : BONJOUR
The value of second string : à tous
Concatenation of first and second string : BONJOUR à tous
Advertisement
# Python - ljust() method example.
# Creating a string
s = 'Smile each day and keep sadness away!'
# Printing the original string
print('Original string is : ', s)
# Calling the ljust() method on string object
# which will return a left justified value of length 30, padded with a space on its right.
print(s.ljust(30))
# Calling the ljust() method on string object
# which will return a left justified value of length 45, padded with # on its right.
print(s.ljust(45, '#'))
# Calling the ljust() method on string object
# which will return a left justified value of length 40, padded with X on its right.
print(s.ljust(40, 'X'))
# Calling the ljust() method on string object
# which will return a left justified value of length 60, padded with 0 on its right.
print(s.ljust(60, '0'))
# Calling the ljust() method on string object
# which will return a left justified value of length 50, padded with @ on its right.
print(s.ljust(50, '@'))
# Calling the ljust() method on string object
# which will return a left justified value of length 45, padded with @ on its right.
print(s.ljust(45, '.'))
Original string is : Smile each day and keep sadness away!
Smile each day and keep sadness away!
Smile each day and keep sadness away!########
Smile each day and keep sadness away!XXX
Smile each day and keep sadness away!00000000000000000000000
Smile each day and keep sadness away!@@@@@@@@@@@@@
Smile each day and keep sadness away!........
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement