0
why does this work like this ?
7 Answers
+ 8
Each line of output is the result of s after a single iteration of the loop. The reason that the output is not all on one line is because the print statement is being called multiple times, and each time it is called, it prints a new line.
If you want the output to be on a single line, you could modify the code as follows:
https://code.sololearn.com/c4xhykL8JzhL/?ref=app
+ 3
Hello,
Well for this, you need to do it in multiple lines.
Firstly, the array word is declared with some data items (4 items).
Then it assigns an empty string to 's'
Next it iterates through each item in the array 'word'
Within the for loop, it assigns what is at 'w' and a space to s
It then outputs the contents of 's'
I do not think this can be done all in one line, at least not from my knowledge, hope that helps
+ 1
Hi, this is the Q&A section. Here you can ask programming related questions. What is your question?
+ 1
thanks š
+ 1
š
0
can you pls explain why it doesn't goes in one line?
0
word=["ER","AS","IQ","NULL"]
s = ""
for w in word:
s += w + " "
print(s)