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=" ")
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
Python one-liner to print the range example.
Do comment if you have any doubts and suggestions on this topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.