+ 2

How to print in python without trailing new line. For instance printing "1,2,3,4,......,n" using for loop

27th Jan 2017, 11:09 AM
Scanner
Scanner - avatar
4 ответов
+ 3
n=10 for i in range(n): print(i, end=' ') end signifies the endline character, the default is '\n' which is a newline by supplying a different one you can control the output you can change it to anything else print(i, end=' ^_^ ')
27th Jan 2017, 4:51 PM
Burey
Burey - avatar
0
for I in range(4): print(I)
27th Jan 2017, 12:30 PM
DerpyOmnister
DerpyOmnister - avatar
0
@DerpyOmnister. the output for your code is 0 1 2 3 But I need 0,1,2,3
27th Jan 2017, 12:53 PM
Scanner
Scanner - avatar
0
print(','.join(str(x) for x in range(10)))
28th Jan 2017, 12:47 AM
Vlad
Vlad - avatar