Output Function in Python
print(object(s),
sep=separator, end=end, file=file, flush=flush) |
How to Use Different Parameter of print():
Parameter |
Description |
object OR object(s), value, Statement |
Any type
of object, and as many (Value & Statement) as you like. This will be
converted it into string value before print on the output screen. |
sep='separator' |
This Field is Optional. Use to separate the
objects value, if there is more than one object. Default separator is use as
' '. (space) |
end='end' |
This
Field is Optional. Use to
print at the end of the line or instruction. Default
is '\n' (line feed) |
file |
This Field is Optional. An object with a write
method. Default is sys.stdout |
flush |
This
Field is Optional. A
Boolean value, specifying if the output is flushed (True) or buffered
(False). Default is False |
Example
1:
Print Single Object Value:-
print("Hello") |
Here print have an object value “Hello”. It’s print on the
output screen.
Example
2:
Print Multiple Object Value:-
print("Hello", "how are you?") OR print("Hello", "how are you?", “ How can I help
You”)
|
Example
3:
Use of Separator “sep”
“Separator is use for the separate an object with the other
object.”
print("Hello", "how are you?", sep="-") OR print("Hello", "how are you?", sep="---") OR print("Hello", "how are you?", sep="Ã ") OR print("Hello", "how are you?", sep="!") |
Output :
Hello
- how are you Hello
--- how are you? Hello
à how are you? Hello
! how are you? |
Example
4:
Use of end parameter
The print method is set to end on a newline by default. It
means there is no need to declare “\n” at the end of the line like other
language C, C++ & Java etc.
print("Life",) print("is
awesome")
print("Life",
end= "\n") print("is
awesome") |
Output is:
Life is awesome
Life is awesome |
So the end option in Python is
used to append any string to the end of the print statement's output.
Like:
print("Life",
end=' ') print("is
awesome")
OR print("Life",
end=' @') print("is
awesome")
|
Here we use Space at the end of the statement.
So the Output is:
Life is awesome
Life@is awesome
|