print()
Function
The print()
function in Python is a key tool for displaying output on the screen. It takes a value, known as the argument, inside the parentheses and prints it.
Basic Usage
Let's start with a simple example, In this example, we print the value "Hello LabEx" to the screen:
>>> print("Hello LabEx")
Hello LabEx
You can use print()
to display the value of a variable:
>>> x = 3
>>> print(x)
3
Moreover, the print()
function allows you to showcase multiple values on the screen by separating them with commas. In this case, print()
automatically adds a space between the value of x and the string "is a number":
>>> x = 5
>>> print(x, "is a number")
5 is a number
print()
also allows you to concatenate values using the plus operator:
>>> name = "LabEx"
>>> print("Hello " + name)
Hello LabEx