Python print: Ways to use print function

The Print function

Python comes up with a print function to display the output. Before version 3.x of Python, the print was used as a statement i.e. it does not require brackets (). Whereas, in the latest version, Python uses print as a function while strings, variables etc has to be enclosed in brackets.

If the print statement is used in the latest version, an error will be generated.

A print example with code

In our examples of Python tutorial, we used the latest method of displaying the output, i.e. using python print as a function, as such it uses version 3.x.

Syntax of print()

Following is the syntax of print function:

Print(“string” or variable_name )

Example of using print function

Following example shows how to use the Python print function to display variable value. The first print function displays a string variable while other displays an int variable by using the print Python function:

The output will be:

This is simple print statement

This will display a string variable

This is mixed string and int 12345

Similarly, you can use the print function in the for loop to display values during the iteration. In this example, we have used a List of Python with six elements. Then a for loop is used to iterate through the list. Inside the for loop, the print function of Python is used to display the List elements.

See the example by clicking the link below:

Output will be

This

is

Python

For

Loop

Example

Also see – Python User input | Python While loop

Was this article helpful?

Related Articles

Leave A Comment?