Print in Python

Print Statement in Python

You can simply print your output with the "print()"

    x = '5'
    print(x)

The output for the above code will be:

5

In python, print statement will automatically take the control to the next line.

For example :

    arr = ['5','4','6','7']
    for x in arr:
        print(x)

The output for the above code will be:

5
4
6
7

Here "arr" is a list/array containing 4 numerical values. We are printing all the values of the array using the for loop. The numbers will be printed one on each line.

How to print values on the same line ?

We can print values in the same line by using a simple syntax shown below.

    print(end = <var-name>)

 For example :

    arr = ['5','4','6','7']
    for x in arr:
        print(end = x)        

The output for the above code will be:

5467