I change the list into a string but it is not printing on the same line
spam= ['apples', 'bananas', 'tofu', 'cats']
for i in spam:
print(str(i))
I change the list into a string but it is not printing on the same line
spam= ['apples', 'bananas', 'tofu', 'cats']
for i in spam:
print(str(i))
Since you are printing each item in the list individually using the for loop, they wont print in the same line. To print them on the same line do the following instead of using a loop:
spam= ['apples', 'bananas', 'tofu', 'cats']
print (', '.join(spam))
Output:
apples, bananas, tofu, cats
You can optionally set a single space to show them separately like the following.
print(' '.join(spam))
Output:
apples bananas tofu cats