Saturday, 5 December 2015

Python: print on same line

The keyword argument end can be used to avoid the newline after the output, or end the output with a different string:

display.py
print(1, 2, 3)
print(4, 5, 6)
print(7, 8, 9)

$ python3 display.py
1 2 3
4 5 6
7 8 9

Update display.py like below.
print(1, 2, 3, end=',')
print(4, 5, 6, end=',')
print(7, 8, 9, end=',')

$ python3 display.py
1 2 3,4 5 6,7 8 9,




Previous                                                 Next                                                 Home

No comments:

Post a Comment