How to Print Without Newline in Python

Sometimes we wants to print string output without newline. Means printing a variable value or statement without going to newline. In Python for printing values print() function is used, which by default ends with newline.

Run below program which prints two string values

You will see following output:

CrazyGeeks.ORG is one of the best Website
in the world.

Now run below code you will see a different output:

The output should be:

CrazyGeeks.ORG is one of the best Website in the world.

Solution

Method 1: If you see above second program carefully, after first print() function comma (,) is used for skipping newline. So to print without newline you can use comma after print function.

For example:

The output should be:

Google is the best search engine.

Method 2: Alternatively you can also use second parameter in print() function which is end where you can assign value like end=" "

For example:

The output should be:

CrazyGeeks.ORG is one of the best Website in the world.

Examples

Example 1: using comma

The output should be:

Apple Pineapple
1 2 3 4 5 6 7

Example 2: using end = " "

The output should be:

Apple Pineapple
1 2 3 4 5 6 7

LEAVE A REPLY

Please enter your comment!
Please enter your name here