Brilyn Bangura
Brilyn Bangura

Reputation: 1

how take out \n when using a 'for' loop with a list?

How do I stop each word being printed out on a new line? I have tried stripping new line using word.strip("\n")

Upvotes: 0

Views: 34

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177971

print has an optional parameter to control the line end:

line = 'The quick brown fox jumped over the lazy dog'
for word in line.split():
    print(word,end=',')

Output:

The,quick,brown,fox,jumped,over,the,lazy,dog,

Ref: print

Upvotes: 1

Related Questions