format() function in python by R4R Team

- format() is one of the string formatting methods in Python,that allows multiple substitutions and value formatting. This method lets us concatenate elements within a string through positional formatting.

Syntax-

str.format(value)

Example-
string is str='{} is a programming language'
then str.format("Python") will return "Python is a programming language"
and str.format("Java") will return "Java is a programming language"


program-

s="{} is a programming"
print(s.format("Python"))
print(s.format("Python"))

s="Avenger is {}"
print(s.format("Awesome"))
print(s.format("Great"))

s='Text is {} the boundary'
print(s.format("between"))


output-

Python is a programming
Python is a programming
Avenger is Awesome
Avenger is Great
Text is between the boundary


-In this program, we use format() function to add string in other given string.




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!