Generally people switching from C/C++ to Python wonder how to print two or more variables or statements without going into a new line in python. Since the python print() function by default ends with newline. Python has a predefined format if you use print(a_variable) then it will go to next line automatically.
For examples:
print("geeks") print("geeksforgeeks") |
will result into this
geeks geeksforgeeks
But sometime it may happen that we don’t want to go to next line but want to print on the same line. So what we can do?
For Example:
Input : print("geeks") print("geeksforgeeks")
Output : geeks geeksforgeeks
Input : a = [1, 2, 3, 4]
Output : 1 2 3 4
The solution discussed here is totally dependent on the python version you are using.
Print without newline in Python 2.x
# Python 2 code for printing # on the same line printing # geeks and geeksforgeeks # in the same line print("geeks"), print("geeksforgeeks") # array a = [1, 2, 3, 4] # printing a element in same # line for i in range(4): print(a[i]), |
Output:
geeks geeksforgeeks 1 2 3 4
Print without newline in Python 3.x
# Python 3 code for printing # on the same line printing # geeks and geeksforgeeks # in the same line print("geeks", end =" ") print("geeksforgeeks") # array a = [1, 2, 3, 4] # printing a element in same # line for i in range(4): print(a[i], end =" ") |
Output:
geeks geeksforgeeks 1 2 3 4
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | Ways to split strings using newline delimiter
- Python | Removing newline character from string
- Print first m multiples of n without using any loop in Python
- Python Program for Print Number series without using any loop
- Python | Ways to print list without quotes
- Python - Ways to print longest consecutive list without considering duplicates element
- Python program to print Calendar without calendar or datetime module
- How to print a semicolon(;) without using semicolon in C/C++?
- Print Hello World without semicolon in C/C++
- C/C++ program to print Hello World without using main() and semicolon
- Print full Numpy array without truncation
- getpass() and getuser() in Python (Password without echo)
- Python Program for Range sum queries without updates
- Python program to count upper and lower case characters without using inbuilt functions
- Finding Mean, Median, Mode in Python without libraries
- Python Program to Count number of binary strings without consecutive 1's
- Image Processing without OpenCV | Python
- Python | Grid Layout in Kivy without .kv file
- Python | Locking without Deadlocks
- Python | All Permutations of a string in lexicographical order without using recursion
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
