Put end = ”parameter at the end of the print method, to works print numbers in the same line in Python.
Note: default python’s print() function ends with a newline.
Example code print numbers in the same line in Python
Simple python example code Printing numbers in the same line.
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for x in list1:
print(x, end=" ")
Output:
![How to print numbers in same line in Python](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2021/07/How-to-print-numbers-in-same-line-in-Python.jpg?resize=352%2C183&ssl=1)
Print range of numbers on same line
Example code in Python 3. You can provide any delimiter to the end field (space, comma, etc.)
for x in range(1, 11):
print(x, end=" ")
Output: 1 2 3 4 5 6 7 8 9 10
Or
Python one-liner to print the range example.
print(*range(1, 11))
Do comment if you have any doubts and suggestions on this topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.