How to Use print() Function in PythonPython Basics


The print() function prints the given message to the screen or other standard output devices.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print("Hello World")
print(1)
print("Hello", "how are you?")

temp = ("A", "B", "C")
print(temp)

Output:

Hello World
1
Hello how are you?
('A', 'B', 'C')

Syntax

print(object(s), separator=separator, end=end, file=file, flush=flush)

Parameters

Name Description
object(s) Any object, as long as you like, will be converted to a string before printed.
sep=’separator’ Specify how to separate the objects if there is more than one object. Default :’ ‘.
end=’end’ Specify what to print at the end. Default: ‘n’ .
file An object with a write method. Default: sys.stdout.
flush A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False.

Return Value

It doesn’t return any value.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us