print method explained in Python
In this post, we will explore the parameters of the print() function.
In Python, the print() function is used to print something on the console. By default, Python prints everything in a new line. But in languages like C/C++ is not by default. To customize the output format Python's print() method has some parameters. They are :
- end
- sep
Consider the below program,
a = [1,2,3,4]
for i in a:
print(i)
When you run the program the output will be,
1
2
3
4
This is the default behaviour of the print method.
end parameter
This is used to end a print statement with any character/string.
If we want to print the above example horizontally, we can use the end parameter.
Example
a = [1,2,3,4]
for i in a:
print(i, end=" ")
The output will be
1 2 3 4
sep parameter
Used to change the separator between the arguments in print().
By default Python uses space as a separator, you can change its character, integer, etc using this parameter.
Example
print( 'a' , 'b' , 'c', sep = "#")
The output will be
a#b#c