Print Function in Python
The print() function prints the given object to the standard output device (screen) or to the text stream file.
Example:
Python
message = 'Hello Ashish!' # print the string message print(message)
The output of the above code is shown below: Hello Ashish!
The use of format method If we have multiple placeholders in a string and want to use the format method to fill them, we can include multiple {} placeholders in the string and pass corresponding values to format() in the same order.
Python
name="Ashish" country="India" print("My name is {}. My country is {}.".format(name, country))
The output of the above code is shown below:
My name is Ashish. My country is India.
Order Matters:
- The first {} will be replaced by name.
- The second {} will be replaced by country.