What is a Print Statement?
Print statement is used to send the output to the computer screen. The message can be string or any other objects.
Syntax
print (objects, sep = ‘seperator’, end = ‘end’, file = file, flush = flush)
Arguments Description
objects | Any objects as many as you like |
seperator | How to separate objects (Optional) |
end | What to print at the end (Optional) |
file | An object with a write method (Optional) |
flush | A Boolean value , By default it is False (Optional) |
HOW TO PRINT A STRING?
To print the string, we have to use the print () Function and inside the double quotes (“”) just enter the string you want to print
PROGRAM
OUTPUT
We can also perform arithmetic operations inside the print () function. Let’s see an example of addition of two numbers.
PROGRAM
OUTPUT
30
HOW TO USE SEPERATOR METHOD?
To use the seperator method we just have to add a parameter to the print () Function which is sep
1) Without using sep method
PROGRAM
OUTPUT
As you can see the strings are separated by space(default). Now by using sep method we can specify how the strings should be separated from each other.
2) Using sep method
PROGRAM
OUTPUT
Python,Programming,Language
As you can see now the strings are separated by comma (,). Similarly, you can decide how you want to separate the strings.
HOW TO USE END METHOD?
To use the end method, we have to pass a parameter to the print () function which is end.
1)Without using end
OUTPUT
10 20
As you can see the output is in the different line but if you want that the end of this line should be with comma (,) you can do that with the help of end method let’s see an example
2) Using end method
OUTPUT
10,20
HOW TO USE FORMAT METHOD?
The format () method formats the specified values inside the string’s placeholder. It returns the formatted string. Placeholder is defined by using curly brackets: {}.
Syntax
String.format(value1, value2)
The Placeholders can be identified using named indexes {object name}, numbered indexes {0} or even empty placeholder { }
Let’s see an example how this format () methods works.
1)Numbered Indexes
PROGRAM
OUTPUT
The two numbers are 10 and 20
2)Named Indexes
PROGRAM
OUTPUT
3)EMPTY PLACEHOLDER
PROGRAM
OUTPUT
There is another way to print statement in python whose syntax is similar to C programming syntax
PROGRAM
OUTPUT
In this way we have discussed the different styles of print statement in python programming.