The print() function in Python is used to output data to the console. Here are the basic usages:
Syntax
print(*objects, sep=' ', end='\n', file=None, flush=False)
Parameters
*objects: The values you want to print. You can pass multiple values separated by commas.sep: A string that separates the objects. Default is a space.end: A string that is printed at the end. Default is a newline character (\n).file: An object with awrite(string)method; defaults to the current sys.stdout.flush: A boolean, ifTrue, the output is flushed (forced to be written immediately).
Examples
-
Basic Printing:
print("Hello, World!") -
Printing Multiple Values:
print("The answer is", 42) -
Custom Separator:
print("Hello", "World", sep=", ") -
Custom End Character:
print("Hello", end="!") print("World") -
Printing to a File:
with open('output.txt', 'w') as f: print("Hello, File!", file=f)
These examples cover the basic usage of the print() function in Python.
