+ 1
how to get output (hello! world! spam! eggs!)
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") #how to get output (hello! world! spam! eggs!)
7 Answers
+ 3
print accepts a keyword argument 'end'. It is defaulted to end='\n'. you can change it to end='! ' to use ! instead and prevent printing to new lines.
words = ["hello", "world", "spam", "eggs"]
for word in words:
print(word, end='! ')
+ 4
Are you missing a space between each word?
+ 1
print (' "hello","word","spam","eggs" ')
+ 1
Bob_Li
words = ["hello", "world", "spam", "eggs"]
print(' '.join(word+'!' for word in words))
+ 1
Amir Ghannad
great idea. Here is a variation:
print('! '.join(words)+'!')
0
for word in words:
words = word + "!"
print(words)
Try this
it is expected you create a variable for the new words you want
0
hide