How to use Python format() to format strings

 


The format() method in Python is a way to format strings. It allows you to put variables and values into placeholders within a template string. This makes it easy to create complex strings without having to write a lot of code.


Here is a simple example:


roll_name = "123"

name = "Angil Baidhawar Chhetri"

class_room = "10"


str = "havingr {0} roll number, his name is {1} study in class {2}"


print(str.format(roll_name, name, class_room))


Previous Post Next Post