ljust() function in python by R4R Team

- ljust() is a python in-build function which operate on the string to shift in the left portion and add some new character

Syntax-

str.ljust(length,fillchar)

- here length is the length of required string
- and fillchar is only one character long.

Example
string is s="mytext"
and we apply s.ljust(10,'1'), then it will become 'mytext1111' of length 10, and old string is shift at left.


program-

print("Enter string")
s=input()
print("Enter character to add")
c=input()
print("Enter length of required string")
n=int(input())
print("original string is ",s)
s=s.ljust(n,c)
print("String after ljust ",s)
print("String length become ",len(s))


output-

Enter string
mytext
Enter character to add
1
Enter length of required string
10
original string is mytext
String after ljust mytext1111
String length become 10


-In this program, we take a input of string and substring to add and input of required length, then with the use of ljust() function we shift the given string at left side.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!