Print in Python
- Authors
- Name
- Brent
Python print() function prints the message you specified to the screen or any output device.
Syntax
print(value(s), sep= ' ', end = '\n', file=file, flush=flush)
Parameters:
- value(s) : Any value, you can sepcify any value. The value will be converted to string before printed
- sep=’separator’ : (Optional) Specify how to separate the objects, if there is more than one.Default :’ ‘
- end=’end’: (Optional) Specify what to print at the end.
- file : (Optional) An object with a write method. Default :sys.stdout
- flush : (Optional) A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False
Return Type: It returns output to the screen.
String Literals
The main purpose of string literals in the print() function of the Python language is to format or design the appearance of a particular string.
\n : Add a new blank line while printing a statement.
“” : To print an empty line.
print("DevThreads, \n learn from developers.")
Output
DevThreads,
learn from developers.
end= ” ” statement
The content that is to be printed at the conclusion of the print() function's execution is specified using the end keyword. It is set to "n" by default, which results in a line change after the print() instruction has been executed.
Example: Python print() without new line
# This print() function ends with "##" as set in the end argument.
print ("DevThreads, learn from developers.", end= "##")
print("Python is fun.")
Output
DevThreads, learn from developers.##Python is fun.
Separator
Any number of positional parameters can be passed to the print() method. These positional arguments are divided using the keyword argument "sep."
Example:
a=03
b=11
c=2022
print(a,b,c,sep="-")
Output
03-11-2022